JavaScript Comments

Comments are notes written inside the code that are ignored by JavaScript.

They are used to:

  • Explain code
  • Improve readability
  • Temporarily disable code
JavaScript Comments

Single-Line Comments

Single-line comments start with //.

Everything written after // on the same line is ignored.

Example:

// This is a single-line comment
let age = 25; // storing age

Multi-Line Comments

Multi-line comments start with /* and end with */.

They are used for long explanations or documentation.

Example:

/*
This is a multi-line comment.
It can span multiple lines.
JavaScript ignores this completely.
*/

Commenting Out Code (Disable Code)

Comments can be used to temporarily stop code from running.

Example:

// console.log("This will not run");
console.log("This will run");

📣 Follow us for more updates:

Follow on LinkedIn Join WhatsApp Channel
Scroll to Top