Comments

Comments are non-executable lines of text in your code. They are ignored by the JavaScript engine when the script runs. Comments are essential for documenting logic, leaving notes for other developers (or your future self), and temporarily disabling chunks of code during debugging.

JavaScript supports two styles of comments:

Single-Line Comments

Use two forward slashes (//) to create a single-line comment. Everything following the slashes on that specific line will be treated as a comment.

// This is a single-line comment
let customerName = "John Doe"; // This comment is at the end of a line of code

Multi-Line Comments

For longer explanations or to comment out large blocks of code, use /* to start the comment and */ to end it. Anything between these markers is ignored.

/*
  This is a multi-line comment.
  It can span across several lines.
  None of this text will be executed as code.
*/
let activeUsers = 500;

Practical Example

Leaving clear documentation about business logic changes is vital. Using multi-line comments helps provide context for other developers reading the configuration settings.

/*
  Attention!
  We are increasing the maximum message length from 140 to 280 characters.
  This allows users to send more detailed content in a single text.
*/

const maxMessageLength = 140;
const newMaxMessageLength = 280;

console.log(
  `Increasing the maximum message length from ${maxMessageLength} to ${newMaxMessageLength} characters.`
);