JavaScript comments can be used to explain JavaScript code, and to make it more readable.
JavaScript comments can also be used to prevent execution, when testing alternative code.
Single line comments start with //.
Any text between // and the end of the line will be ignored by JavaScript (will not be executed).
Example of single line comment:
// Change paragraph:
document.getElementById("p1").innerHTML = "This is paragraph";
// Change heading:
document.getElementById("h1").innerHTML = "This is heading";
Multi-line comments start with /* and end with */.
Any text between /* and */ will be ignored by JavaScript.
Example:
/*
this is
multi line comments
Soopro pathshala
provides online and offline training
on various courses
*/
In JavaScript, comments are used to explain code, improve readability, or temporarily disable parts of code during debugging. There are two types of comments:
Start with //.
Anything after // on the same line is ignored by the JavaScript engine.
Start with /* and end with */.
Can span multiple lines and are often used for detailed explanations or to comment out large blocks of code.