javascript comment : easy how to

Posted under javascript sample code On By mohammed.mutawe

JavaScript comment

When writing advanced JavaScript code, the difficulty of parsing the code will begin to appear again, which leads to taking a lot of time in analyzing the code, especially when you modify the functions of many lines. JavaScript is like other languages, and it provided writing comments aside to make it easier for developers.

 

Concepts

  • Types and forms of comments.
  • Do an example.

 

Definition

You can add a comment in one line, and all you will do is reserve one line from the editor only to write your notes as follows:

<script>
// I am javascript comment
</script>

Or you can write your comment after executing a specific command in JavaScript as follows:

<script>
 document.write("Javascript code here !");// I am javascript comment
</script>

 

There are many ways that you can activate or deactivate the JavaScript code, and you can do this by:

<script>
// document.write("I deactivated this code by considering as a comment!");
</script>

You can also add multiple line comment to become like so :

/*
You can do this by creating multiple lines of comment
to become like this
and this is very effective way if you want to write paragraph comment
*/

 

Example

After we explained how to use comment correctly you can put these lines of code in your page to see difference between them

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Types of comment in javascript</title>
  <link href="style.css" rel="stylesheet" />
</head>
<body>
  <script>
/*Welcome to javascript comment definition
you learned how to create first comment by using multiple line
*/

// you learned how to create first comment by single line

  </script>
</body>
</html>

 

References

  • Third edition JavaScript

Leave a comment

Your email address will not be published. Required fields are marked *