Javascript Comments

Basically comments are used to include notes or suggestions or warnings to JavaScript code. This can make it easier to read and understand. Comments can also be used to disable code to prevent from execution.

JavaScript supports both C-style and C++-style comments:

  • Text written after // is treated as a comment and is ignored by JavaScript. This is used for a single line comment.
  • Text written between the characters /* and */ is treated as a comment. This may span multiple lines.
  • JavaScript also recognizes the HTML comment opening sequence is not recognized by JavaScript so it should be written as //-->.

Javascript Single Line Comments Example

Javascript Multi Line Comments Example