JavaScript Comments – JavaScript Single Line and Multiline Comments

Rawat Digamber /  Read Time: 1 minute
JavaScript comments are used to interpret JavaScript code, comments are used to make the other programmers or developers understand the code easily.

JavaScript comments are not executed by the browsers. JavaScritp offers two types of comments.

1. JavaScript – Single Line Comment

Single line comments are depicted by the two forward slashes //.

Check out the example for single line comment.

// Update header:
document.getElementById("header").innerHTML = "Hello World!";

// Update sidebar:
document.getElementById("sidebar").innerHTML = "Hey There!";

A single line comment above every line of code is very useful to make us understand the code.

2. JavaScript MultiLine Comment

JavaScript Multi-line comments begin with /* and end with */ symbol. The comment which goes between /* — comment here — */ will not be executed by the browser.

We've declared 3 values variables and assigned 
3 numerical values to all those 3 variables.

let x = 2;

let y = 4;

let z = 8;

JavaScript Multiline of comments is usually good for creating documentation.

Written by Digamber

I am passionate about solving real-world problems through algorithms and functional programming. I love to create modern web and mobile apps using Node JS, Mongo DB, React JS, Angular 2+, Firebase Real-time NoSQL Database, Ionic Framework, Object Oriented JavaScript, RxJS, TypeScript, jQuery etc...