JS part syntax

Source: Internet
Author: User

The statements provided by JavaScript fall into the following major categories:

1. Variable declaration, assignment statement: var.

The syntax is as follows: var variable name [= initial value]

Example: var computer = 32//definition computer is a variable and has an initial value of 32.

2. Function definition statement: Function,return.

The syntax is as follows: function name (parameters with functions)

Function Execution Section

The return expression//return statement indicates the value that will be returned.

Example: function square (x)


Return x*x


3. Conditions and Branching statements: If...else,switch.

The If...else statement completes the branching function in the program flow block: If the condition is true, the program executes the statement or block of statements immediately following the condition, otherwise the program executes the statement or block of statements in the else. The syntax is as follows: if (condition)

EXECUTE Statement 1


EXECUTE Statement 2

Example: if (result = = True)

Response = "You answered right!" ”


Response = "You are wrong!" ”

The Branch statement switch can take a different approach depending on the value of a variable.

The syntax is as follows: switch (expression)


Case LABEL1: statement string 1;

Case LABEL2: statement string 2;

Case LABEL3: statement string 3;


Default: statement string 3;


If the value of the expression does not match any of the statements provided in the program, the statement in default is executed.

4. Loop statement: for, For...in,while,break,continue.

The syntax for the FOR statement is as follows: for (initialization part; condition part; Update section)

Executive section ...

As long as the condition of the loop is established, the loop body is repeatedly executed.

The for...in statement is a little different from the for statement, and it loops through all the properties of an object or all the elements of an array.

The syntax for the for...in statement is as follows: for (variable in object or array)



The continuous test condition controlled by the while statement, if the condition is always true, loops until the condition ceases to be true.

The syntax is as follows: while (conditional)

Execute statement ...


The break statement ends the current various loops and executes the next statement of the loop.

The continue statement ends the current loop and immediately begins the next loop.

5. Object Operation statement: With,this,new.

The syntax for the WITH statement is as follows:

With (object name) {

EXECUTE statement


The effect is this: if you want to use many of the properties or methods of an object, simply write out the name of the object in the () of the WITH statement, and then direct the property name or method name of the object to the following execution statement.

The new statement is an object constructor that you can use to define an object.

The syntax is this: the new object name = The real object name

For example, we can define a new Date object like this: Var curr= new Day (), and then the variable Curr has the properties of the Date object.

The This operator always points to the current object.

6. Comment Statement://,/*...*/.

This is a single-line comment

/* This can be a multiline comment .... */

JS part syntax

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.