JavaScript Overview and Syntax

6. Where to place the <script> element?

6.3. Comments in JavaScript


          You can leave comments throughout a JavaScript, allowing you to leave reminders and explanations in your code. Comments may be useful if another developer is editing the code in the future.

          The following are the two ways of incorporating comments in JavaScript:

        • For a single line comment, two slash characters (//) are used at the beginning of a line. You may place a single line comment on the same line as a declaration, as long as it comes after a statement. It is not appropriate to close a single line comment, as a line break effectively closes it.

// This is a comment with a single line.

        • The same syntax that you learned from CSS can be extended to multi-line comments. The browser disregards everything inside the /**/ characters and considers it as a comment.
/* This is a comment with several lines. Anything that goes here is completely ignored when the script is executed.
There is a need to close this type of comment. */