The global function and branching structure of JavaScript Foundation

Source: Internet
Author: User
Tags switch case

1. * * * Function:

Declaration in advance: before the formal execution of the program, pre-read the Var declaration of variables and function declaration functions, centralized to the * * Current Scope * * The top of the creation, and the assignment left in place.

2. Global functions: The functions that the browser manufacturer has implemented, as specified in the ES standard

You do not need to use any objects, you can call directly

decodeURI () Decodes the URI of an encoding.
decodeURIComponent () Decodes a coded URI component.
encodeURI () Encodes a string as a URI.
encodeURIComponent () Encodes a string as a URI component.
Escape () Encodes a string.
Eval () Computes the JavaScript string and executes it as script code.
GetClass () Returns the Javaclass of a javaobject.
Isfinite () Checks if a value is a number that has a poor size.
IsNaN () Checks whether a value is a number.
Number () Converts the value of an object to a number.
Parsefloat () Parses a string and returns a floating-point number.
parseint () Parses a string and returns an integer.
String () Converts the value of an object to a string.
Unescape () Decodes a string encoded by escape ().

Branching structure:

1. a condition, one thing, to be satisfied is done ( not satisfied on nothing to do )

If the operation is simple: Short circuit: Condition && ( operation 1, operation 2,...)

If the operation is complex:

if ( condition ) {

Code snippet to be executed if the condition is met

}

2. a condition, two things, the second choice one executes

If the operation is simple: three mesh : condition ? Operation 1: Operation 2

If the operation is complex:

if ( condition ){

Code snippet to be executed if the condition is met

}else{

Code snippets that do not meet the criteria

}

3. multiple conditions, multiple events, multiple choice one execution

If the operation is simple, or only a different value is returned: three mesh:

Condition 1? Operation 1/ value 1:

Condition 2? Operation 2/ value 2:

...    ...:

Default Action / value ;

If the operation is complex or may not be performed at all:

if ( condition 1) {

code snippet to be executed only if condition 1 is met

}else if ( condition 2) {

code snippet to be executed only if condition 2 is met

}... {

...

}[else{

Default code Snippet ( executes only if all of the above conditions are not met )

}]

Emphasis: There may only be one if after the code snippet is executed and subsequent if no longer judged

If the conditions are all congruent comparisons, use the switch case instead of the else if structure,

"Customer service Key selection function case:"

Switch ( expression ){

Case Value 1:

The code snippet executed when the value of the expression = = = value 1

Break

Case Value 2:

The code snippet executed when the value of the expression = = = value 2

Break

...  :

...

[Default:

Default code snippet executed when the value of the expression and the above values are not equal ]

}

Switch Case vs Else if

Switch case is more efficient than else if

else if You can customize the comparison condition to solve all problems

The switch case limit condition can only be compared with the same equality.

Break: Exit the current structure

When not to break: When the same code is executed ina contiguous two case

The global function and branching structure of JavaScript Foundation

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.