JavaScript Comments

JavaScript comments are annotations in the code that are ignored by the JavaScript engine when the code is executed. They are used to explain code, make notes, or temporarily disable certain parts of the code. Comments are helpful for both the developer writing the code and others who might read or maintain the code in the future.

There are two types of comments

Single-Line Comments

Single-line comments are used to add short notes or explanations on one line.

They start with // and extend to the end of the line.


// This is a single-line comment
let name = 'John'; // Variable name is assigned the value John

Multi-Line Comments

Multi-line comments are used for longer explanations or for commenting out multiple lines of code.

They start with /* and end with */


/*
This is a multi-line comment.
It can span multiple lines.
It is useful for longer descriptions or temporarily disabling blocks of code.
*/
let x = 10;