About Javascipt Basics 2

Source: Internet
Author: User
Tags arithmetic operators logical operators

To undertake the essay of the previous essay

The following is about logical thinking about the same as the programming language

Iv. operators

1. Arithmetic Operators (+-*/%) add, subtract, multiply, divide, and balance, where% is the remainder operation

example: var total = (1 + 4) * 5;

var i = 100;

var temp = (i–20)/2;

Alert ("ten" +)//return 1020;

Alert (+)//return 30;

2. Post increment/decrement operator + +,--

example: var i = 10;

var a = i++; (equivalent to i = i + 1)

Alert (a); (value is 10?) Why is it? because it is preceded by a post increment, a before I increases by 1 the value of I is obtained)

var i = 10;

var a = ++i;

Alert (a); (so The value is 11)

3. comparison operator (<, >=, <=, = =,!=,===,!==)

Example: Alert (> 5); Outputs True

var i = 100;

var n = 100;

Alert (i = = n); Outputs true;

Alert (i! = n); Outputs false;

Alert (i = = n)//outputs true; (all equals required numeric and type Equality)

4. Logical Operators (&&, | |,!)

&&: logic and (true after Current)

|| : Logical OR (current after which one is true will be True)

! : Logical non (true to False is false to True)

example: var i = 8;

Alert (i<5 && i<10); Outputs false (8 is not less than 5 so the former is false because it is && so it is False)

Alert (i > | | i < 10); Outputs true (8 is not greater than 100 so the former is false then 8 is less than 10 so the latter is true because it is | | So That's True)

Alert (! ( > 5)); Outputs false (10 greater than 5 is true and then because it is!) Not true so it is False)

The precedence of an operator is previously incremented, then *,/,%, then +,-, then compared (<,>,<=,>=,!=), and finally logic (&&,| |,! )

V. JavaScript annotations

Single-line Comment

/* ... * * Multi-line comment

Note: multi-line annotations cannot be nested with each other

Vi. Program Flow control (branch Statements)

first, Conditional Statement If syntax:

If (condition) statements1 else statement2

example: if (> 5) {alert ("hello world");}

var i = 90;

If (i >) {alert (i + "greater than 100");} (first use if to determine if I is greater than 100 if the statement is executed in curly braces if it is not transferred to else Execution)

else if (i >) {alert (i + "greater than 80");} (this else also has if to determine the remaining process is the same as Above)

Else{alert (i + "less than 100");}

second, Switch Statement syntax:

Switch (expression) {case value://statement, case value://statement break; default://statement}

example: var i = 25;

Switch (i) {(switch to determine the expression in Parentheses)

Case 25:alert (i + "equals 25"); (executes The statement if the result of the expression corresponds to a Type)

Break (prevent continued Execution)

Case 100:alert (100);

Break

Default:alert (' Other '); (executes The statement if it does not correspond to the value of the Case)

}

The next statement about the loop

About Javascipt Basics 2

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.