Single-line and Multi-line Comment | Javascript Comment


In this article we will learn about JavaScript comment - Single-line and Multi-line comments.

Comments in any programming are used to explain the code and to make it more readable of developers.

Sometimes it is also useful when we quickly want to comment-out a code block to stop its execution during testing or debugging our codes.

Single-line Comment in JavaScript

Single-line comment are use to comment on one full line or a part of a line.

We can use single-line comment to explain a code in the same line or use it in debugging by comment out a code to prevent its executions.

To write a single-line comment, we have to start the text after two forward slashes // . And everything written after that until the end of the line break will be considered as a JavaScript Comment.

Lets see some example.

const a = 'animel' //declaring a variable

//this is a code to add two numbers
let a = 1
let b = 1
let c= a+b

Multi-line Comment in JavaScript

Multi-line comment do the same work as single-line. But With Multi-line you can comment out multiple lines in one go.

The comment blocks start with two symbol: /* and ends with */ . And anything written between them are considered as JavaScript Comment.

Lets see this example.

/* this is javascript comment
and the code is 
to add two number */
let a = 1
let b = 1
let c= a+b

Related Topics:

Add New Line In JavaScript With Code Example


💾 Recommended Articles