JavaScript Basic Syntax Two

Source: Internet
Author: User

1. Relational operators

Greater than ' > ', greater than or equal to ' >= ', less than ' < ', less than equals ' <= ', equals ' = = ' ' = = ', not equal to '! = ' '!== ', the return value of the relational operator is Boolean type True or FALSE.

Example: var a = 5 > 3;   alert (a); 5>3 is correct, so Alerta (a) is true.

var a = 5 >= 3;alert (a); 5>=3 is correct, so alert (a) is true.

When the ' = = ' and '! = ' are in a relational operation, if the type is not the same, the type is converted to a value comparison.

var a = ten = = ' ten '; alert (a); Type is different, first convert to number type and then compare, true.

var a = 5! = ' 5 '; alert (a); It is also the first conversion type after comparison, false.

' = = = ' and '! = = = ' Comparison is only possible if the type is the same

Example: var a = 5 = = = ' 5 '; alert (a); The type is different at this time, so the result is false.

var a = 5!== ' 5 '; alert (a); At this point the types are different, that is, the left and right sides are not equal, true.

2. Logical operators

Logical and &&, logical OR | |, the return result of a logical operator is a Boolean type.

Logic and &&: only if all the expressions are the result is true, the result of the entire logical expression is true, otherwise false.

Example: var a = 5 > 3 && 2 <4; alert (a); 5>3 and 2<4 are all true, so the result of the entire expression is true.

var a = 3 >= 3  && -1>0; ALETRT (a); true;

Logical OR | | : As long as there is an expression in all expressions, that is true, the dog is False

3. If branch statement

Three kinds of structure of the program:

Sequential structure: Top to bottom, sequential execution

Branching structure: First judge the condition, the condition is established, execute the branch statement

Loop structure: Executes a code repeatedly when the current condition is met

if (conditional expression) {

Statement 1

} else{

Statement 2

};

4. Switch Branch

switch (expression) {

Case value 1;

Statement 1;

Break

Case value 2;

Statement 2;

Break

Case value 3;

Statement 3;

Break

......

Default

Break

}

Finds the appropriate case branch based on the value of the expression, executes the branch statement, and defaults to the default branch if it does not find the correspondent branch.

In the Switch branch statement, the break statement is used to end the spoke statement.

5, trinocular operator

var a =, B = 0, c = +;

c = a > B?    A:B; A and B compare, if a>b, then the value of a is assigned to C, if a is smaller than B, the value of B is assigned to C.

alert (c);

6, Window.onload

Window.onload = function () {

Alert (' Load complete ');

}

The Window.onload event waits until all elements of the page content including the picture are loaded and executed after the

JavaScript Basic Syntax 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.