JavaScript Comments


Comments are lines in your JavaScript code that are ignored by the JavaScript engine. They are used for explanations, notes, reminders, or temporarily disabling code. There are two main types of comments: single-line comments and multi-line comments.

Single-Line Comment

Single-line comments are used for short explanations. They begin with // and everything after it (on the same line) becomes a comment.

Syntax:

// This is a single-line comment

// This is another single-line comment. // No matter how long the text is, as long as it stays on one line, // it remains a single-line comment.


Multi-Line Comment

Multi-line comments are used when you need longer explanations spanning multiple lines. They begin with /* and end with */.

Syntax:

/* This is a multi-line comment */

Examples:

/* HTML is for the structure CSS is for the design JavaScript is for the behavior */

/* The quick brown fox jumps over the lazy dog */


HTML Logo