Javascript learning notes (2) JavaScript core statements

Source: Internet
Author: User

Statement

Syntax

Purpose

Break

Break;

BreakLabel;

Exit the innermost loop or switch statement, or exit the label specified statement.

Case

CaseExpression:

Mark a statement in the switch statement

Continue

Continue;

ContinueLabel;

Re-start the innermost loop or re-start the cycle specified by label

Default

Default:

Mark the default statement in the switch

Do/while

Do

Statement

While (Expression);

An alternative form of WHILE LOOP

Empty

;

Do nothing

For

For (Initialize;Test;Increment)

Statement

An easy-to-use Loop

For/in

For (VariableInObject)

Statement

Traverse the attributes of an object

Function

FunctionFuncname([Arg1[...,Argn])

{

Statements

}

Declare a function

If/else

If (Expression)

Statement1

[ElseStatement2]

Conditional executionCode

Label

Identifier:Statement

ToStatementSpecify a nameIdentifier

Return

Return [Expression];

Returns the value of an expression by a function or by a function.

Switch

Switch (Expression){

Statements

}

Use Case orDefault: multi-branch statements marked by statements

Throw

ThrowExpression;

Throw an exception

Try

Try {

Statements

}

Catch (Identifier){

Statements

}

Finally {

Statements

}

Capture an exception

VaR

VaRName_1[=Value_1]

[,...,Name_n[=Value_n];

Declare and initialize a variable

While

While (Expression)

Statement

A basic loop statement

With

With (Object)

Statement

Extends the current scope chain (not supported)

Switch language: In JavaScript, the case expression matching the switch language is determined by the = equivalent operator, rather than the = equal operator.

For/in statement: For (variable in object) statement;
Provides a method to traverse object attributes. As follows, for/In cyclically enters all attribute names and their values of an object,
For (VAR prop in my_object ){
Document. Write ("name:" + Prop + "; Value:" + my_object [prop] ");
}
In fact, the for/in loop does not traverse all possible attributes of all objects. Some attributes of an object are marked as read-only, permanent (undeletable), or non-enumerated in the same way. These attributes cannot be enumerated using the for/in loop.

With statement: With statement can greatly reduce the amount of input code, but it runs much slower than the equivalent code that does not use with statement. In addition, function definitions and variable initialization in the with statement may produce unexpected behavior. Therefore, we recommend that you avoid using the with statement.

Null statement: NULL statements do not execute any operations. However, in practice, it is found that null statements are useful when creating a loop with null subjects.

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.