Describes the basic syntax requirements of the JavaScript language and the basic syntax of the javascript language.

Source: Internet
Author: User

Describes the basic syntax requirements of the JavaScript language and the basic syntax of the javascript language.

What are the basic syntax requirements of JavaScript? We will answer the following questions one by one:

I. Case Sensitive
The JavaScript language is case-sensitive. The two strings are considered to be different strings with the same case.Keywords in JavaScript are also case sensitive and should be in lower case as required by syntax.
Ii. Writing format
JavaScript ignores the blank space between statements, that is, space between statements, blank lines, indentation, and so on.To improve the readability of the program, these formats should be used to make the program clearer and more readable.
Iii. Comment statement
To improve the maintainability and readability of the program, some comments should be provided,It is for the reader. There are single-line and multi-line comments. Single-line comments start with a double slash, and multiple rows are marked with "/*" and "*/" as the start and end.

<Script type = "text/javascript"> // location of the JavaScript code (single line comment) function theAlert (textToAlert) {alert (textToAlert );} /* define a function named theAlert, which includes the textToAlert parameter. The function body calls the internal function alert () of the JavaScript language to output parameters. (Multiline comment or block comment) */theAlert ("Hello World"); // call the defined function output parameters </script>

Iv. Use of semicolons
In JavaScript, the statement ends with a semicolon.Some code, such as the loop structure or the conditional statement with the structure selected, does 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 a semicolon is added, the content following the Condition Statement is executed no matter whether the value of a is 1. The condition test fails.
V. JavaScript placement
JavaScript code can be placed in the The start part of the tag, which must be declared as a JavaScript script. If JavaScript code is not directly placed on an HTML page
For example, MyPage. js, you can use the src attribute of <script> to link it:

<script type=”text/Javascript”src=” MyPage.js”>

6. Reserved Words in JavaScript
JavaScript retains some words for special purposes. They are called Reserved Words and cannot be used for the names of constants, variables, identifiers, and so on. There are also some special words that cannot be used for naming to avoid ambiguity.
Now let's write a simple JavaScript development example: by running the program, output a "Hello World" statement. Procedure:
(1) Start VS 2010, create a website named Ch-2.aspx, Default homepage is Default. aspx. Find the website name in the "solution Resource Manager" window on the right, right-click it, and select "Add new item" from the shortcut menu ".

Click Add.

(3)on the mypage.htm Page, place the cursor between <title> and </title>, and change the title to My First Page. Add the code to be executed after the tag <title> </title>.

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

(4) Select "Save all" in the "file" menu to save the written code.

(5) to run the program, select "start debugging" from the "debug" menu, press the function key F5 on the disk, or click "start debugging" in the toolbar. A prompt box is displayed.

The above code is used in the HTML parsing process of the browser:
First, open the script tag and declare it as JavaScript, that is, the following line of code:

<Scripttype = "text/Javascript">

Then, declare a function theAlter () and use the textToAlter parameter, which calls the internal function alter () to complete the display function. The following code is used:

FunctiontheAlter (textToAlter ){
Alert (textToAlter );
}
Finally, call this function by assigning a value to the parameter. The parameter is enclosed in quotation marks: "Hello World !". That is, the following line of code:
TheAlter ("HelloWorld ");

The above are the basic syntax Requirements for the JavaScript language, hoping to help you better learn Javascript programming.

Related Article

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.