What is the JavaScript single line comment character?

青灯夜游
Release: 2021-11-04 16:29:26
Original
4265 people have browsed it

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.

What is the JavaScript single line comment character?

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:

//注释内容
Copy after login

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>
Copy after login

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 赋值给它
Copy after login

[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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!