JavaScript Comments
Sometimes we need to write something in the code, which we wish should not execute with the code. It can be some explanation of what the particular line of code does, or if you suddenly remember while writing the code that you have to get some items from the grocery store, and you want to add those items to your code so that you don’t have to remember it (Just kidding). But if there is anything you wish should not execute with the code, but still, want to be there in the code, you can use comments.
Comments in JavaScript
So, comments are something that is ignored by the browser. You can say that the browser considers that you wrote those lines for some personal purpose and ignore that particular line. Even if there is a commented code, it will be ignored just because it is a comment.
The comments are also of two types –
- Single line comment →
A single-line comment is one that is written in a single line.
On a line, anything you write after // would be a single-line comment. - Multiline comment →
The multiline comment is one that can be written in multiple lines.
Anything written between /× and ×/ would be considered a comment. You will get this actually when you will see a comment.
Here is an example that can help you understand the concepts of comments.
As you can see, the comments are being displayed in a different color as well. You can write comments in your programs, whenever you require them. You can use single-line comments and multiple-line comments in your program as per your requirement.