comments in javascript

comments in javascript

comments.

so what is a comment in javascript, well a comment is being used to make code more readable and easy to understand by developers it explains line by line or a block of code in javascript and what does it exactly do, there are 2 types of comments in javascript, single line comment, and multiple lines comment that we normally use them to describe how and why the code works.

single-line comment starts with // - while the multiple-line comment starts with /*

let's see an example.

let x = 5; // declare x and give it a value of 5

let y = x+1; // declare y and give it value of x which is 5 plus value of 1

document.getElementById("p").innerHTML = "My first paragraph."; //changing paragraph.


/*

The code below will change

and the paragraph with id = "P"

in my web page:

*/

document.getElementById("P").innerHTML = "My first paragraph.";


To view or add a comment, sign in

Explore content categories