Home >Web Front-end >JS Tutorial >Detailed explanation of the basic syntax requirements of JavaScript language_Basic knowledge
What are the basic grammatical requirements of JavaScript language? The following will give you the answers one by one:
1. Case sensitive
JavaScript language distinguishes characters between uppercase and lowercase characters, and two strings with the same case but different cases are considered to be different strings. JavaScript language keywords are also case-sensitive and should be lowercase according to grammatical requirements.
2. Writing format
JavaScript Language ignores the gap between words, that is, the space between the sentences, the empty line, the indentation, etc.
In order to improve the readability of the program, these formats should be used to make the program clearer and more readable.
3. Comment statements
In order to improve the maintainability and readability of the program, there should be certain comment statements.
It is for people who read the program. There are single-line comments and multi-line comments. Single-line comments Comments start with a double slash, and multiple lines start and end with /*,*/.
<script type="text/javascript">//JavaScript代码放置的位置(单行注释) function theAlert(textToAlert) { alert(textToAlert); } /* 定义一个名字叫theAlert的函数,此函数带一个参数textToAlert。 函数体内调用JavaScript语言的内部函数alert()输出参数。(多行注释或块注释) */ theAlert("Hello World");//调用定义的函数输出参数 </script>4. Use of semicolons
The statements in the javascript language ends in the segment.
Some codes, such as loop structures or conditional statements of selection structures, do not need to be followed by a semicolon, otherwise the execution path of the original structure will be changed.
For example: if(a==1): After adding a semicolon, the content after the conditional statement will be executed regardless of whether the value of a is 1, and the conditional test fails.
5. Where to place JavaScript
JavaScript code can be placed in the 93f0f5c25f18dab9d176bd4f6de5d30e9c3bca370b5104690d9ef395f2c5f8d1 tag in the HTML page, or it can be placed in the 6c04bd5ca3fcae76e30b72ad730ca86d36cc49f0c466276486e50c850b7e4956 tag, in the 3f1c4e4b6b16bbbd69b2ee476dc4f83a
At the beginning of the tag, the user needs to declare that it is a JavaScript script type. If the JavaScript code is not placed directly on the HTML page, but in another file
, such as MyPage.js, you can use the src attribute of 3f1c4e4b6b16bbbd69b2ee476dc4f83a to link to it:
<script type=”text/Javascript”src=” MyPage.js”>
So now let’s write a simple JavaScript development example: by running the program, a "Hello World" statement is output. Specific steps:
(1) Start VS 2010, create a website, name it Ch-2.aspx, and the default homepage is Default.aspx. Find the website name in the "Solution Explorer" window on the right, right-click it, and select "Add New Item" from the pop-up shortcut menu.
(2) In the opened "Add New Item" dialog box, the installed template options are listed, select the "HTML Page" option, name it "MyPage.htm" in the name dialog box below, and then click Click the "Add" button.
(3) On the MyPage.htm page, position the cursor between b2386ffb911b14667cb8f0f91ea547a7 and 6e916e0f7d1e588d4f442bf645aedb2f, and change the title to My First Page. Then add the code to be executed after the tag b2386ffb911b14667cb8f0f91ea547a76e916e0f7d1e588d4f442bf645aedb2f.
(4) Then select "Save All" in the "File" menu to save the written code.
(5) To run the program, select "Start Debugging" in the "Debug" menu, or press the function key F5 on the keyboard, or click the "Start Debugging" button in the toolbar. The running result displays a prompt box.
The working process of the above code in browser HTML parsing:
First, open the script tag and declare it to be JavaScript, which is the following line of code:
f4790f932f4388221dde92a0034d6969
Then, declare a function theAlter(), using the parameter textToAlter, which calls the internal function alter() to complete the display function. That is the following piece of code:
functiontheAlter(textToAlter) {
alert(textToAlter);
}
Finally, the function is called by assigning a value to the parameter, which is enclosed in quotes: "Hello World!". That is the following line of code:
theAlter("HelloWorld");
The above is the basic grammatical requirements of the JavaScript language introduced to you. I hope it can help you better learn Javascript programming.