JavaScript Statement Classification Encyclopedia

Source: Internet
Author: User
Tags expression function definition integer return variable

Core tips: JavaScript Statement Classification Encyclopedia

1, assignment statement: Var

2.return statement

3, Conditional branch statement If...else,switch

4, circular statement for,for...in,while,break,continue.

5, the object operation statement With,new,delete,this

6. Comment Statement

7. Function definition statement: Function,return

1. Variable declaration assignment statement: VAR

The Var statement declares the name of a variable and can also have an initial value for that variable.

If the Var statement declares a variable in a function, the valid region of the variable is limited to this function, called a local variable, and if the Var statement is outside the function body, the active area is the entire application, called the global variable.

It is possible to declare a variable outside the function body without using VAR and give the value of the variable. (but Var is recommended)

The syntax for VAR is as follows:

Cases:

 


var computer=9//computer is an integer variable with an initial value of 9
Computer=9//computer is an integer variable with an initial value of 9
2.return statement

The return statement indicates the value that will be returned by the function.

The syntax is as follows:

return expression;

If the expression is omitted here, or there is no return statement at the end of the function, this function returns a value of the undefined type.

3, Conditional branch statement If...else,switch

1.if...else

1) Basic format

if (expression)

statement paragraph 1;

......

Else

statement paragraph 2;

......

2 function: If the expression is true, then execute the statement paragraph 1, otherwise execute statement paragraph 2.

3) Description:

The if-else statement is the most basic control statement in JavaScript, which allows you to change the order in which statements are executed.

• The expression must use a relational statement to implement the judgment, which is evaluated as a Boolean value.

• It converts 0 and nonzero numbers to false and true respectively.

• If the statement after if has more than one line, you must enclose it with curly braces.

4 Nesting of IF statements

if (Boolean) statement 1;

Else (Boolean) statement 2;

else if (Boolean) statement 3;

......

Else Statement 4;

In this case, each level of the Boolean expression will be computed, if true, then execute its corresponding statement, otherwise execute else after the statement.

Example:

<script>
function ABCD ()
{
var d=confirm ("Please select OK or cancel");
if (d==1) {
Alert ("You choose to be sure");
}
else{
Alert ("You choose to cancel");
}
}
</script>

5). Switch statement

A branch statement switch can take a different approach depending on the value of a variable.

The syntax for the switch is as follows:

switch (expression) {

Case Label 1:

Execute the statement;

Case Label 2:

Execute the statement;

......

Default:

Execute the statement;

}

Example:


<script>
var d= new Date ();
Switch (d.getdate ()) {
Case 0:document.write ("Monday");
Case 1:document.write ("Tuesday");
Case 2:document.write ("Wednesday");
Case 3:document.write ("Thursday");
Case 4:document.write ("Friday");
Case 5:document.write ("Saturday");
Case 6:document.write ("Sunday");
}
</script>

1 2 Next page > full text reading tips: Try "←→" button, turn the page more convenient Oh!

[1] [2] Next page



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.