Which of the following is the correct way to write a comment in JavaScript?

Which of the following is the correct way to write a comment in JavaScript?

a) # This is a comment
b) // This is a comment
c)
d) /* This is a comment */

Answer:

b) // This is a comment

Explanation:

In JavaScript, single-line comments are written using // at the beginning of the comment. For multi-line comments, /* */ is used.

Example of both single-line and multi-line comments:


// This is a single-line comment

/*
 This is a multi-line comment
*/
    

Comments are ignored by the JavaScript engine and are used to explain the code or leave notes for other developers.

Reference:

JavaScript MCQ (Multiple-Choice Questions)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top