What Is Comment Tag In JavaScript ?

Using a comment tag in JavaScript projects is a perfect way to make your code more understandable and to remember why you write a code. As such, there are code comment tags in the JavaScript language as well as comment tags in HTML, PHP and many other languages.


Before the JavaScript uses the comment tag, these code comment tags are divided into two main headings. We can use JavaScript code comment tags in two different ways: Single Line comment tag and multiple lines.



JavaScript Comment Tag

Above we mentioned that JavaScript comment codes are divided into two. These comment tags If you want to make a comment next to a code snippet, all you have to do is use the single line comment tag. For example :

document.write(5 + 6); // Returns the sum of 5 and 6

In the above code snippet, as you have seen, we have indicated what it means. JavaScript understands the single-line code comment tag with two slash marks // next to each other, and you can stop the execution of that code by placing these two side-by-side slash marks in front of a code snippet. Since that line will enter into the comment line, that code will no longer work and will not print anything on your screen.


If we want to include more than one line in the comment tag, we can use the multi-line comment tag by putting one mark at the beginning and one mark at the end of each line without placing two individual side-by-side slash marks. In this way, since the code snippets in it will appear as comments, they will not print anything on the screen and will become inoperable.

document.write(5 + 6);
/* document.getElementById("demo").innerHTML = "Merhaba JavaScript";
window.alert(5 + 6); */

In the code snippet above, we used / * slah and asterisks to start the JavaScript comment line. After that, we put the * / star to the place where we want to close the multi-line comment tag, then slash it and we have now converted the remaining part of these two tags into the comment line.


Comment tags are usually one-to-one to use when you write a code and don’t want it to work at the moment, or to indicate why you’re writing it, why you’re writing it, what you’re doing. Sometimes it can be used to tell what you use where and for what purpose when you send the code to another person. But in general, the purpose is to look at the future when you look at your code why you do this or why you need to add something here later, reminding you, never appear on the screen, and therefore we need a label that only source code.

Leave a Reply

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