JavaScript Comments

JavaScript Comments

Not all JavaScript statements are “executed”.
Comments are lines of code that JavaScript will intentionally ignore. Commenting is a way that you can:

  • Leave no to other developers.
  • Describe what your code does.
  • Leave notes to yourself for the future.
  • Comment out a part of the Javascript code without deleting it.

There are two ways to write comments in JavaScript:

  • Single-line Comment
  • Multi-line Comment

Single Line Comments

Single line comments start with  // ( two forward slashes).
Anything you write after these double slashes will be ignored by JavaScript (will not be executed).
This example uses a single-line comment before each line of code:

// This is my first JavaScript program
document.write("Hello World!");

// That is my second JavaScript program
window.alert(5 + 5);

Multi-line Comments

Multi-line comments start with /* and end with */.
Any text between /* and */ will be ignored by JavaScript.

/* This is a multi-line comment */

This is another

Comments are closed.