JavaScript-based arithmetic operators, back-and-forth increment/decrement operators, comparison operators, logical operators, program flow control

Source: Internet
Author: User
Tags arithmetic arithmetic operators switch case

1. Arithmetic Operators

Add, subtract, multiply, divide, and balance, where % is the remainder operation

+ operator

A. If the plus sign is a string, then the plus sign is connected.

B. If both sides of the plus sign are numeric, then the plus sign is added.

C. If the plus sign is a string, the function of the plus sign is to connect.

var num1 = 123var string1 = "123" Console.log (NUM1 + string1)//This is the + operator is the link effect, the result is 123123console.log (NUM1 + num1)  //Both sides are number Value, the + operator is additive, and the result is 246

the -operator is an operation between two numeric values. The * operator is the multiplication of two values The /operator is the division of two values residual, modulus remainder:10/3 = 3.....1; 1 is the remainder .

Shorthand for the operator:

A = a + 2;   A + = 2;a = A-2;   A-=2;a = a * 2;   A*=2;a = A/2;   A/= 2;a = a% 2;  a%=2;

  

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

Self-increment:

    var a = 1;    var B = 2;

First add: ++a;

var C = A + + b++;//usually see first plus, first calculate Gaga,//And then calculate

After add: a++;

var c = ++a  +  ++b;  All see after Add, first to remove Gaga, remove after the calculation//To obtain the results after the self-gaga
self-reducing--a and a--are also

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

Alert (> 5);//true

  

var i = 100;var n = 100;alert (i = = n);//true;alert (i! = n);//false;        alert (i = = N)         

  

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

&&: Logic and (and)

&& Features: A flase is false

|| : Logical OR (OR)

|| Feature: A true is true.

! : Logical non (take reverse)

var i = 8;alert (i<5 && i<10);  False (i > | | i <);  True (! ( > 5));  False

  

precedence of logical operators:

! > && > | |

() >*,/> +,-

 5. Program Flow Control

If ... else structure:

if (condition) {code One}else {Code II}

If...else If ... else:

if (condition) {code block 1}else if (condition/boolean) {code block 2}else {code block 3}

  

Switch Case:

Switch (variable) {case Variable value 1: code block 1;break;case Variable Value 2: code block 2;break;case Variable Value 3: code block 3;break;.....default: Default code block; break;}

  

Attention:

1.case can have any number of

2.case must have a break in the knot part.

The colon after the variable value of 3.case

4.default can write or not write, but if you do not write, the conditional code will be terminated directly.

JavaScript-based arithmetic operators, back-and-forth increment/decrement operators, comparison operators, logical operators, program flow control

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.