How to use comments to prevent JavaScript Execution?

If you want another code while working in the same code document, then use comments. Comment the previous code and add the alternative code to test it. After the testing completes, uncomment the previous code. In this way, you can test both the codes.

While using comments follow the below rules to create valid comments −

  • Any text between a // and the end of a line is treated as a comment and is ignored by JavaScript.

  • Any text 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 //-->.

The following example shows how to use comments in JavaScript.


Updated on: 2019-07-30T22:30:21+05:30

337 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements