Backbencher.dev

Comments

Comments in JavaScript is a piece of text that is not taken for execution. JavaScript engines ignore the comment text. Comments are purely for adding usability and readability of code.

Single Line Comment

As the name tells, a Single Line Comment is restricted to one line.

// This is a single line comment

////// Another single line comment //////

Any text that comes between // and end of the line is ignored by the JavaScript engine.

Multi Line Comment

We can also place a comment by wrapping the text between /* and */. This enables having multi-line comment.

/* This is a multiline comment.
It spans three lines.
Oh! I am the third line. */

Nested Comment

Since the end of this comment is marked using */, things will go wrong if we try to nest multiline comment.

/* Parent comment starts
/* Nested comment */
Parent comment continues */

In the above example, the third line is not part of comment and will throw error.

Last updated on 21 Sep, 2022
Joby Joseph
Web Architect