JavaScript Basic Sharing II

Source: Internet
Author: User

Precedence of Operators

with parentheses in the first parentheses. again multiplication add and subtract after

if we need to prioritize the ascending operator sentence: parentheses

second, Process Control

Sequential structure, branching structure, loop structure!

Sequential Structure

The code is executed and parsed from the top to the next line!

Branching Structure

Although there are many ways to choose, but we often can only choose a road in practice!
If statement,switch statement

if statement

Single-branch, dual-branch, multi-branch

Single branch:

Format:

if ( conditional expression ) {

statement block

}

Description: If the conditional expression is set Get Boolean true to EXECUTE statement block

Note: If a single-branch parenthesis is behind this pair of curly braces can be omitted without writing but it is recommended not to omit!

Dual Branch:

Format:

if ( conditional expression ) {

statement block 1

}else{

statement block 2

}

Description: If the conditional expression is set Get Boolean true to EXECUTE statement block 1 But if the conditional expression does not hold the Boolean false will execute the statement block 2

Multi-branch:

Format:

if ( conditional expression 1) {

statement block 1

}else if ( conditional expression 2) {

statement block 2

} else if ( conditional expression 3) {

statement block 3

} else if ( conditional expression N) {

statement block N

}[else{

statement block

}]

Description

L  first step: first to determine the conditional expression 1 is the establishment of   if established get boolean true    will EXECUTE statement block 1   If not set   get false   2 is

L Second Step: It is recommended that the first step is not established on the basis of judging the conditional expression 2 If it is set up Boolean True will execute the statement block 2 if not established by the /c5>false to determine whether the conditional expression 3 is true

L Third Step: It is suggested that the second step is not established on the basis of the first to determine whether the conditional expression 3 is established if it is set up will execute the statement block 3 if not established We'll judge the next conditional expression.

L If none of the above conditional expressions are true and we write the else statement, then the statement block in the else is executed.

L Else statements can be omitted do not write can be written according to the actual situation to decide

Switch statement

Format:

Switch ( variable name ) {

Case Value 1:

executing a statement block 1

Break

Case Value 2:

executing a statement block 2

Break

Case Value 3:

executing a statement block 3

Break

Case Value N:

EXECUTE statement block N

Break

Default

Default block of statements

Break

}

Description

The value of the variable name is compared to each value in the case. If the comparison is true, the corresponding statement block will be executed, but it will find out if the corresponding block of statements is followed by the keyword "break". If it does not write it will continue to look for The break keyword and will also be the following statement block output directly to find break !

Example: Dynamic output day of the week

First step: We want to get to the system time date

a time-date object was created

Objects are made up of properties and methods!

Step two: from the time Date object inside gets to one day of the week

Looping Statements

What do you mean loops?

When satisfied with certain conditions, repeat to do one thing!

For Loop, while Loop ,do ... while loop

for Loop

Format:

For ( variable initialization ; Conditional Expressions ; Variable Update ){

Loop Body

}

Structure Description:

First step: variable initialization   declare a variable and assign it a value it only executes once

Step Two: Determine if the conditional expression is true If the conditional expression is set take the third step, exit the loop if the conditional expression is not true

Step Three: Establish the second step on the basis of establishment Execution Loop Body

Fourth Step: variables are updated Take the second step immediately. determine if the conditional expression is true!

1---à2---à3--à4---à2--à3--à4

Example 1: Use a for loop to output ten Hello!

Example 2: Output 1-100!

Example 3: Output 100-1

Example 4: Request out the 1-100 between the and!

Example 5: Finding The odd and 1-100 between

People from small to large, have played a vulgar game:

game Play method is, everyone turns off, if the report can be divisible by 7 number, or the mantissa is 7 of the number, are counted on the mine. You should be punished for singing.

Please output all "security numbers" between 1~60 in the console.

Like what:

1,2,3,4,5,6,8,9,Ten, One, A, -, the, -, -, +, -, A, at, -, -, -, in, -...

Example 7, the output of a ten -row table This table to achieve the effect of interlaced color!

Example 8: Output a table with 1 rows and 9 columns!

Example 9: Output a table with 9 rows and 1 columns!

example : Output a table with 9 rows and 9 columns

example : Output a multiplicative table!

while loop

Format:

Variable initialization

while ( conditional expression ) {

Loop Body

Variable update

}

Structure Description:

When a conditional expression is set The loop body is executed !

Do ... .. while loop

This loop is a variant of the While loop!

Format:

Variable initialization

do{

circulation body ;

Variable update

}while ( conditional expression );

Structure Description:

first the loop body is executed, then the conditional expression is determined to be true! The loop body is executed whenever the conditional expression is true !

The number that can be divisible by 3 between 1-100!

The difference between a for loop and a while loop:

The for loop is primarily used when the number of loops is known

While is typically used for unknown loops

the difference between a while loop and a do ... while loop

The while loop first determines whether the conditional expression is true

Do.. While executing a secondary loop body regardless of whether the conditional expression is true, it executes the loop body once more to judge the conditional expression!

third, the cyclic interrupt keyword

Break,continue

Break effect

when the break keyword is encountered then the entire loop Loop will not continue to execute!

Continue Effect

The "This" loop is interrupted after encountering the Continue keyword , and the next loop continues!

Iv. replenishment of knowledge points

Window.prompt (Text,defaulttext)

L User Input dialog box

L Text: prompt information optional

L defaulttext: Optional default display of data

L Get a String type of data when the user clicks the OK button !

L If the user does not fill in the data directly click the Cancel button to get null

parseint ( variable name ): Extracts an integer from a string when it encounters a non-numeric value, stops extracting if the first character of the string is not a value, return NaN directly

parsefloat ( variable name ): Extracts a floating-point number from a string when encountered except . other characters will stop extracting if the first character of the string is not a value then return directly NaN

IsNaN ( variable name ): The variable name is converted to an automatic number type if the conversion is NaN then return true, returns false If it is not NaN

JavaScript basic sharing two

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.