How to use Comment in JavaScript

In this article I am going to explain about Java Script comment.
  • 2129

JavaScript Comment

In JavaScript If we want to any line or any code that should be executed then we use comment. Comment mainly use for explain the JavaScript and make code more readable. In other word we can say that we use the comment for prevent the execution of any code or any statement.

Types of comment

Single line comment its starts with //

<html>

<head>

    <script type="text/javascript">

    //This is the single line comment

       // my function name is myfun()

        function myfun() {

        }

    </script>

</head>

<body>

    <button onclick="mufun">

        Click</button>

</body>

</html>

Multi line comment its start with /* and end with */

<html>

<head>

    <script type="text/javascript">

        /*This is the Multi line comment

        my function name is myfun()*/

        function myfun() {

        }

    </script>

</head>

<body>

    <button onclick="mufun">

        Click</button>

</body>

</html>

 

Using comment for Avoid the execution. In this example we are using comment for avoid the execution of function

 

<html>

<head>

    <script type="text/javascript">

 

        /*  function myfun() {

        alert("Hello How are you");

        }*/

    </script>

</head>

<body>

    <button onclick="mufun">

        Click</button>

</body>

</html>

 

Using comment at the end of line

 

<html>

<head>

    <script type="text/javascript">

 

        function myfun() {

            alert("Hello How are you"); // It is a function

        }

    </script>

</head>

<body>

    <button onclick="mufun">

        Click</button>

</body>

</html>

Further Readings

You may also want to read these related articles: here
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.