Commenting your code may seem arbitrary, but doing so while you’re writing your code may just save you lots of time and frustration when you need to look back through your code and understand your thought process at the time.

What type of comments does JavaScript support? Multiple-line C-style comments, One-line comments of C++ style, and One-line comments with the HTML comment-opening sequence.

What are C-style comments?

Everything within

/*

and

*/
is a comment.
Here’s an example of multiple-line C-style comments:
/* This is a comment */

/* C-style comments can also span to
as many lines as you'd like,
as this sentence is showing here. */
How about one-line comments of C++ style?
This type of comment begins with
//
and continues up to the next line break –
// This is a one-line comment!
Then there are one-line comments with the HTML comment-opening sequence
(<!--).

Keep in mind that the JavaScript interpreter ignores closing characters
of HTML comments (-->).
Here’s an example:
<!-- This is a one-line JavaScript comment
<!-- It works just like a comment beginning with //
<!-- --> This is also a one-line JavaScript comment
<!-- --> Because JavaScript ignores the closing characters
<!-- --> of HTML comments
<!-- --> This is also a one-line JavaScript comment
HTML-style comments are not commonly found in the middle
of JavaScript code since // comments are easier to follow and read later.
It’s advised however to use HTML comments rather than // comments so that the code is hidden from older or outdated browsers.