How to Write Comments in JavaScript?
Understand the purpose of comments in JavaScript and learn how to write both single-line and multi-line comments. This lesson helps you write clearer, more readable code by using appropriate commenting techniques, similar to styles used in languages like C++ and Java.
We'll cover the following...
We'll cover the following...
We often place comments in our code so that we know what it is doing.
JavaScript is similar to C++ and Java in its commenting style:
- Everything between
/*and*/is ignored by the interpreter. - Everything after
//on the same line is ignored by the interpreter.
The above two comments are interpreted as:
Everything else is ignored.
Why do we use comments? To avoid ending up in similar situations:
My other favorite is:
Try to write readable code with good comments.