JavaScript Comments

Why comments?

JavaScript comments make codes more legible. It is also used to describe certain parts of the code. For example: Software companies use comments in typed codes. The reason: if the software writer writing that code leaves the job (or for some other reason), someone else will write that code. If we think of it as a high project, it would be very difficult or too long for the person reading these codes to understand those codes. Therefore, code cannot be written without using comments. This is not a rule but it has like tradition.

In other words: Our goal in developing the program; understanding of our codes by the machine. But besides, the people in this program should understand the code you wrote. Otherwise, they won’t know what you’re doing. This makes the program very complex.


Single Line Comments

It is very simple to use. Example:

        // If the username is empty:
        alert("The username cannot be blank");

        // If the password is empty:
        alert("The password cannot be blank");

In the above example, a single line comment was written.

Single-line codes:

  // You can write the you want to specify here.

Multi-line Comments

Sometimes single-line comments may not see your business. If you are going to comment too much, it will be such a use:

 // You can write the you want to specify here. 
// You can write the you want to specify here.
// You can write the you want to specify here.
// You can write the you want to specify here.
// You can write the you want to specify here.
// You can write the you want to specify here.

It can be done. But this is not preferred. How to use multi-line comments:

  /*

You can write the you want to specify here.

*/

Another function of the comments: If we write the code in the comments, we will cause those codes not to work. For example:

//document.write("HELLO WORLD")

or:

/*
console.log("HELLO WORLD")
console.log("HELLO WORLD")
*/

as a result ; you need to use comments if you are a good software developer or want to be a good software developer

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create a website or blog at WordPress.com

Up ↑

Design a site like this with WordPress.com
Get started