To explain the basic grammar requirements of the JavaScript language _ basic knowledge

Source: Internet
Author: User

What are the basic grammar requirements for JavaScript language? Here are a few answers:

One, case sensitive
The JavaScript language is case-sensitive, with two strings different from the same case, and is considered a different string. the keywords in the JavaScript language are case-sensitive, and should be lowercase if required by syntax.
ii. format of writing
The JavaScript language ignores whitespace between statements, i.e. spaces between statements, blank lines, indents, and so on. to improve the readability of your program, you should use these formats to make your program clearer and more readable.
third, the annotation statement
in order to improve the maintainability and readability of the program, there should be a certain comment statement, which is read by the person reading the program, with Single-line and multiline annotations, Single-line comments starting with double slashes, and multiple lines beginning and ending with/*,*/.

<script type= "Text/javascript" >//javascript where the code is placed (single-line comment) 
 function Thealert (texttoalert) { 
 alert ( Texttoalert); 
 } 
 /* 
 define a function named Thealert, which takes a parameter texttoalert. 
 the Internal function alert () output parameter of the JavaScript language is called in the function body. (Multiline comment or block annotation)/ 
 Thealert ("Hello World")//Call function output parameter defined 
 </script> 

Iv. use of semicolons
The statement ends with a semicolon in the JavaScript language. some code, such as a loop structure or a conditional statement that chooses a struct, does not need a semicolon, or it changes the execution path of the original structure.
For example: if (a==1): After adding a semicolon, regardless of whether A's value is 1, the content following the conditional statement is executed, and the condition test fails.
v. Location of JavaScript placement
JavaScript code can be placed inside At the beginning of the label, the user is required to declare the 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 link it using the src attribute of <script>:

<script type= "Text/javascript" src= "Mypage.js" >

Six, reserved words in JavaScript
JavaScript retains a part of the word used for specialized purposes, called reserved words, and cannot be used for naming constants, variables, identifiers, and so on. There are also special words that cannot be used to name them in order to avoid ambiguity.
Now write a simple example of JavaScript development: By running a program, you output a "Hello world" statement. Specific steps to operate:
(1) Launch vs 2010, set up a Web site, named Ch-2.aspx, default homepage for Default.aspx. In the Right Solution Explorer window, locate the site name, right-click, and select Add New Item from the shortcut menu that pops up.

(2) The installed template options are listed in the Open Add New Item dialog box, and the HTML page option is named "Mypage.htm" in the following Name dialog box, and then the Add button is clicked.

(3) on the mypage.htm page, position the cursor between <title> and </title>, and change the title to my-page. Then add the code to be executed after the label <title></title>.

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> 
 
 
 

(4) then select "Save All" from the File menu to save the written code.

(5) To run the program, select Start Debugging on the Debug menu, or press the function key on the keyboard F5, or click the "Start Debugging" button in the toolbar. The run result displays a prompt box.

The above code works in the browser HTML parsing process:
First, open the script label, which is JavaScript, which is the following line of code:

<scripttype= "Text/javascript" >

Then, declare a function thealter (), using the parameter texttoalter, which calls the intrinsic function alter () to complete the display function. This is the following section of code:

Functionthealter (texttoalter) {
alert (Texttoalter);
}
Finally, by calling this function by assigning a value to the parameter, the arguments are enclosed in quotation marks: "Hello world! ”。 This is the following line of code:
thealter ("HelloWorld");

The above is for you to introduce the JavaScript language basic grammar requirements, hope to be able to help you better learn JavaScript programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.