JavaScript Comments – JavaScript Single Line and Multiline Comments

Article By Digamber Rawat on
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.

Digamber Rawat

Feel free to contact me, If you are looking for a freelance full stack Developer, with the following skills: Mongo DB, Express JS, Angualr 2+, Node JS, Loopback JS, Firebase, Ionic Framework and WordPress. I also offer remote contracting service to the clients across the globe. Hire Me