In JavaScript, a single-line comment is represented by double forward slashes "//", which can be used before and after a statement. Its syntax is such as "//This is a single-line comment", which means "//" All characters after the symbol until the end of the line will be ignored by JavaScript.
The operating environment of this article: Windows 7 system, javascript1.8.5, Dell G3 computer.
How to comment in a single line in javascript?
Single-line comments
In JavaScript, single-line comments are represented by double forward slashes (//) and can be used before and after a statement.
Syntax:
// 你的代码在这里
All characters following the // syntax until the end of the line will be ignored by javascript.
Example 1: Add
<script> //这是单行注释 document.write("hello javascript"); </script>
before the statement Example 2: Add
<script> var a=10; var b=20; var c=a+b; document.write(c);//输出10和20之和 </script>
after the statement Related video tutorial sharing: javascript advanced video
The above is the detailed content of How to comment in a single line in javascript. For more information, please follow other related articles on the PHP Chinese website!