JS Comments

HTML
CSS
C#
SQL

JavaScript Comments

A comment is simply a line of text that is completely ignored by the JavaScript interpreter. Comments are usually added to provide extra information about the source code. It will not only help you understand your code when you look after some time but also others who are working with you on the same project.

Advantages of JavaScript Comments

JavaScript comments offer two key advantages:

– To make code easy to understand, It helps explain things so that anyone can follow along without getting confused.

– To prevent code from running unnecessarily, comments come in handy. Occasionally, we include code to carry out certain tasks. However, later on, there might be a reason to stop that code from executing. In such situations, using comments is a smart choice.

Types of JavaScript Comments

JavaScript supports two types of comments:

Single-line Comment:

It is represented by double forward slashes (`//`), it can be used before or after a statement. 

Example of a single-line comment before the statement:

Example of a single-line comment after the statement:

Multi-line Comment:

Represented by a forward slash with an asterisk (`/*`) and an asterisk with a forward slash (`*/`), it can be used for both single and multi-line comments.

 Example of a multi-line comment:

Course Video