Last updated

JavaScript Comments

Definition: A comment is text the browser ignores. Comments explain the code to people, not the computer.

Example 1 — single-line comments

Anything after // on a line is ignored:

// This is a comment
console.log("Hello");  // this note is ignored too

Example 2 — multi-line comments

Wrap longer notes between /* and */:

/* This comment
   spans several
   lines */
console.log("Done");

Example 3 — switching code off

Put // in front of a line to stop it running without deleting it — handy for testing:

console.log("This runs");
// console.log("This is switched off");

💡 Good habit: explain why, not the obvious what. Helpful comments make future-you grateful.

Try it Yourself
Output

          
Ad · responsive