How to write comments in JavaScript

Topic: HTML / CSS« Prev|Next »

Answer: Use the Syntax "// text" and "/* text */"

Comments in CSS are typically used to explain the purpose of the style rules declarations. It will help you and others to understand what you were trying to do with the style rules at the time of editing style sheets. Comments are not displayed by the browsers.

Single Line Comments

JavaScript single line comment begins with //, See the example below:

  • <script type="text/javascript">
  •     function helloWorld(){
  •         alert("Hello World!"); // alert "Hello World!" in the browser
  •     }
  • </script>

Multi-line Comments

JavaScript multiple line comment begins with /*, and ends with */.

  • <script type="text/javascript">
  •     /*
  •     The function below display
  •     an alert dialog with "Hello World!" message
  •     */
  •     function helloWorld(){
  •         alert("Hello World!");
  •     }
  • </script>

Related FAQ

Here are some more FAQ related to this topic:

 
Close

Your Feedback:

 

We would love to hear from you! Please say something.