The basic grammar of js needs to pay attention to the small details

javascrip basic grammar

One, js annotation

Multi-line comments, the content in the comments will not be executed, but can be viewed in the source code.
To develop a good comment habit, you can also adjust the code through comments

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">    
    <meta name="viewport" content="width=device-width, initial-scale=1.0">    
    <title>Document</title>    
    <script type="text/javascript">
            /*        
            js注释多行注释        
            */        
            //js单行注释    
    </script>
</head>
<body>    
</body>
</html>

Two, js is strictly case sensitive

Demo code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">    
    <meta name="viewport" content="width=device-width, initial-scale=1.0">    
    <title>Document</title>    
    <script type="text/javascript">
    //document.write是像body里面写入内容
   	document.write('你好帅哥!')
	document.write('你好美女!')
	Document.write('你好哥哥')
    </script>
</head>
<body>    
</body>
</html>

Webpage effect: The
Insert picture description here
result shows that the third code is not executed! This is js is strictly case sensitive
Insert picture description here

Every statement in js ends with a semicolon (;)

The function of (;) is to tell the browser that over, this sentence is over.
If you don’t write a semicolon, the browser will automatically add it, but it will consume a certain amount of system resources, which will affect the performance of the browser. It is also possible that the system will add an error and cause your code to be wrong. Therefore, during development, a sentence must end manually. Add a semicolon.

Multiple spaces and newlines are ignored in js, so we can use spaces and newlines to format our code to ensure the clarity of the code.

Guess you like

Origin blog.csdn.net/weixin_46475440/article/details/108461758