Home > Article > Web Front-end > What is the JavaScript single line comment character?
In JavaScript, the single-line comment character is "//", and the syntax is "//comment content", which is only valid for the line in which it is located; and all content after "//" will be regarded as the content of the comment. , but will not affect the content before "//", so it can be used at the end of the code.

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
In JavaScript, a single-line comment starts with double slashes "//", and the single-line comment symbol is "//". The syntax format is:
//注释内容
Single-line comments// are only valid for the current line. All content after
// will be regarded as comment content, and the content before // will not be affected. The sample code is as follows:
<!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
</head>
<body>
<div id="demo"></div>
<script>
// 在 id 属性为 demo 的标签中添加指定内容
document.getElementById("demo").innerHTML = "http://c.biancheng.net/js/";
</script>
</body>
</html>Single-line comments can be used at the end of the code, as shown in the following example:
var x = 5; // 声明变量 x,并把 5 赋值给它 var y = x + 2; // 声明变量 y,并把 x+2 赋值给它
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of What is the JavaScript single line comment character?. For more information, please follow other related articles on the PHP Chinese website!