All TalkersCode Topics

Follow TalkersCode On Social Media - A Social Media Network for developers Join Now ➔

How To Comment In JavaScript

Last Updated : Mar 11, 2024

How To Comment In JavaScript

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">
    <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="">
        h1 {
          color : rgb(95, 194, 95) ;
          font-size: 25px;
          font-weight : bolder ;
        <h1> WELCOME TO TALKERSCODE </h1>
        <h3> How To Comment In JavaScript </h3>
        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) ;
  1. To write HTML code <! DOCTYPE html> to mention which version of the HTML file is written in.
  2. Then we have to write the <html> tag used to define the root of an HTML document. And also write the ending tag </html>.
  3. <head> tag used here to use to contain the metadata about the HTML file and end it with </head> tag
  4. Then <title> tag is used to set the title of the HTML document and end it with </title> tag.
  5. Attach an external CSS file using <link> tag to give style to the page
  6. <h1> tag used to add heading here and also adding the inline CSS here.
  7. Create a <Script> tag to write JavaScript within it.
  8. Create two Variables using var a and b.
  9. Write a single-line comment using two forward slashes//.
  10. Creating another variable c which is equal to sum of both variables a and b
  11. Now write multiple line comments starting with /* and ending with */
  12. 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.

Author Image About Amruta

Amruta is an Experienced web developer with 4 years for experience she completed her master's with MCA and passionate about programming Languages for creating technical contents like HTML, CSS, JavaScript, Java, Python, PHP, jQuery.

Follow Amruta On Linkedin 🡪