JavaScript Learning Summary

Source: Internet
Author: User
Tags function definition

A function declaration statement usually appears at the top of the JavaScript code, or it can be nested inside other functions. When nested, however, the function declaration can only be present at the top of the nested function. Therefore, a function definition cannot appear in an if statement, a while loop, or any other statement, precisely because of this limitation of the position of a function declaration, the ECMAScript standard specification does not classify a function declaration as a true statement.

function declaration statements and function definition expressions contain the same function names, but they are still different. The new function object is created in both ways, but the function name in the function declaration statement is a variable name, and the variable points to the function object. As with var declaration variables, functions in a function definition statement are explicitly "advanced" to the top of a script or function. So they are visible throughout the script and in the function.

All nested functions in a script can be declared before other code in the current context. That is, you can call it before declaring a JavaScript function.

As with the Var statement, variables created by a function declaration statement cannot be deleted. However, these variables are not read-only and variable values can be overridden.

Conditional Statement

A conditional statement determines whether to execute or skip some statements by determining the value of an expression. These statements are the decision points of the code, sometimes referred to as "branches." If the JavaScript interpreter is executed according to the "path" of the code, the conditional statement is the bifurcation point on the path, and the program must select one of the paths to continue execution.

A switch statement is a more complex, multiple-branching conditional statement.

If statement

As with most programming languages, the IF, else matching rule in JavaScript is that else always matches the nearest if statement. In order to make the example more readable, easier to understand, easier to maintain and debug, the curly braces should be used appropriately: {}, insisting on doing so can avoid ambiguity in the program.

Using else if is clearer and preferable.

Cycle

To understand conditional statements, you can think of code in JavaScript as a branch path. A loop statement is a loop of a program's path that allows a part of the code to be executed repeatedly. The most commonly used loop is the traversal of an array element.

Using while (true) creates a dead loop.

JavaScript interpreter

for (Initialize;test;increment)

Statement

Initialize initialization operation

Test cycle condition judgment

Update of Increment counter variable

Dead loop for (;;)

For (variable in object)

Statement

Variable is usually a variable name, an expression that can produce a left value, or a variable declared through a var statement, which must be a value that applies to the left side of an assignment expression.

Statement is a statement or statement block that forms the body of a loop.

Label statement

Statements are labels that are made up of identifiers and colons that are preceded by statements:

Identifier:statement

Any statement can have many labels.

The WITH statement is used to temporarily extend the scope chain, syntax:

With (object)

Statement

The With statement is usually used to simplify code writing when the object nesting level is very deep.


           --the JavaScript Authority Guide (sixth Edition). Beauty David.flanagan. Chinese version "

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.