JavaScript Comments

Single-Line Comments

Single-line comments are used to comment out a single line of code. They begin with //.

Tutorials dojo strip

Explanation of Code:

  • The text following // is ignored by the JavaScript engine and is not executed as code.
JavaScript

Multi-Line Comments

Multi-line comments are used to comment out multiple lines of code. They begin with /* and end with */.

Explanation of Code:

  • Everything between /* and */ is ignored by the JavaScript engine.
JavaScript

Using Comments for Code Documentation

Comments are not just for temporarily disabling code. They are also used to explain the purpose of code, making it easier for others (or yourself) to understand it later.

Explanation of Code:

  • Comments explain what the code does and the significance of each variable.
JavaScript

JavaScript Comments Example Code

Explanation of Code:

  • Single-Line Comment: Used to describe the variable declaration.
  • Multi-Line Comment: Used to explain the calculation.
  • End-of-Line Comment: Used to document the output of the console.log statement.
HTML

JavaScript Labs

Tutorials dojo strip