Javascript – How to add comments

Please follow & like us :)

Here are the syntax to add comments in Javascript.

1 Double Trailing Slash – “//”

Example Code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        //calling alert
        alert('test');
    </script>
    <script src="js/helloworld.js"/>
</head>
<body>
    <script>
        alert('test');
    </script>
</body>
</html>

2 Use asterisk – /** */

Example Code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        //calling alert
        /**
         * calling alert
         */
       
alert('test');
    </script>
    <script src="js/helloworld.js"/>
</head>
<body>
    <script>
        alert('test');
    </script>
</body>
</html>