JavaScript Comments

In this chapter, you will learn about two different types of comments that the JavaScript programmer allows to use.

What are the Comments in Javascript?

Comments are those lines within a program or script which the compiler or interpreter does not read when they compile or interpret any source code.

There are two ways to include comments in JavaScript.

ECMA-Script standardizes for JavaScript the C-style comments for both single-line comments as well as block comments. The single-line comment starts with two forward-slash characters, such as:

Syntax:
// comment applied for one line

A JavaScript block comment begins with a forward slash and asterisk (/ *) and ends with the opposite (* /), as in the example below:

Syntax:
/*

* This is the way of using multiline

* Comment...

*/

It is to be noted that even though the second and third lines contain an asterisk, these are not necessary and are included in the above code for clear readability.


Scroll Back to Top