JavaScript Comments

JavaScript comments are used to describe JavaScript code. These lines are not displayed in the website. It offers an option of leaving notes for yourself or others. The JavaScript comment simplifies the production of more readable code. There are two types of JavaScript comment:

  • Single-line Comment
  • Multi-line Comment


Single-line Comment

A single-line comment is represented by //. It is used for commenting a single line.

Example:

<script type="text/javascript">
// This is a single line comment
document.write("num2")
</script>

Run Example


Multi-line Comment

Multi-line comments open with /* and close with */.

Example:

<script type="text/javascript">
/*
This is a multi-line comment
This is a multi-line comment
This is a multi-line comment
*/

document.write("num2")
</script>

Run Example