How To Comment In JavaScript
Last Updated : Mar 11, 2024
IN - JavaScript | Written & Updated By - Amruta
In this article we will show you the solution of how to comment in JavaScript, we can write comments in JavaScript anywhere in the code. they are ignored by the web browser and don't affect the working of the program.
Writing comments along with code helps you and helps whoever tries to understand it.
Single Line Comment :-
represented by two forward slashes (//)
//console.log("this is single line comment") ;
Multiple-line Comment: if we want to comment down multiple lines, we use multiple-line comments. it is represented by a forward slash and one asterisk (/* */)
/* console.log("this is multiple line comment") ; console.log("this is multiple line comment") ;*/
Step by step guide on how to comment in JavaScript :-
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title> how to comment in javascript </title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css"> <style> h1 { color : rgb(95, 194, 95) ; font-size: 25px; font-weight : bolder ; } </style> </head> <body> <center> <h1> WELCOME TO TALKERSCODE </h1> <h3> How To Comment In JavaScript </h3> </center> <script> var a = 20 ; //this is the first variable var b = 50 ; //this is the second variable var c = a + b ; /*this is the sum of the variables is c sum = variable1+variable2 */ console.log(c) ; </script> </body> </html>
- To write HTML code <! DOCTYPE html> to mention which version of the HTML file is written in.
- Then we have to write the <html> tag used to define the root of an HTML document. And also write the ending tag </html>.
- <head> tag used here to use to contain the metadata about the HTML file and end it with </head> tag
- Then <title> tag is used to set the title of the HTML document and end it with </title> tag.
- Attach an external CSS file using <link> tag to give style to the page
- <h1> tag used to add heading here and also adding the inline CSS here.
- Create a <Script> tag to write JavaScript within it.
- Create two Variables using var a and b.
- Write a single-line comment using two forward slashes//.
- Creating another variable c which is equal to sum of both variables a and b
- Now write multiple line comments starting with /* and ending with */
- Using console.log() to display the sum of both variables.
Conclusion :-
At last, here in conclusion, we can say that with this article’s help, we know how to comment in JavaScript.
I hope this article on how to comment in JavaScript helps you and the steps and method mentioned above are easy to follow and implement.