Logical Operators Operator syntax Math comparison operator assignment operator shorting

Logical Operators:

&&: logical and operator   : Summary: it is really only true, false is a fake

|| logical OR operator   Summary: are false only false, it is a really true

! Logical NOT operator

! True false results

! False true results

Non-Boolean logic operation results are not necessarily involved in value is a Boolean value

 

Implicit true: number other than 0, non-empty string

Implicit false: "", 0, NaN, undefined, null

Short circuit syntax:

a && b: if a is true, the result is B; if a prosthesis, the results of a

a || b: if a is true, the result is a; if a false result b


 

Operators

Math is a built-in object js

Math.random (): random number;: can not write; results are floating point numbers between 0 and 1

Math.pow (,): the power operation; parameters: a parameter index results in base two parameters are numerical results of calculated power

Math.sqrt (): root operation parameters: a parameter to prescribe the numerical results: prescribing value

Math.PI pi [pi] (Properties)  

 


Comparison Operators

> Greater than

<Less than

> = Greater than or equal

<= Less than or equal

== equal

=== congruent

! = Not equal

! == equal to incomplete

(As long as the comparison operators, the result must be Boolean

  1. Boolean value when null involved in computing, implicit conversions. true (1) false (0) null (0), a special null participate == , === When not converting 0
  2. When implicit conversion is purely numeric string participate.
  3. == equal, the judge let both sides of the relationship on both sides as equal as possible. Only determined values are the same, judging whether the data type is not equal.
  4. === full equal, ranging as far as possible so that the relationship between both sides. And judges whether the same type and value
  5. ! = Not equal, and == is the opposite. ! == as long as is true, then it must be = false; as long as == is false, then = must be true!
  6. ! == equal incomplete, and === are opposites. ! === long as is true, then it must be == false;! === long is false, then it must be true ==
  7. Both sides are string comparisons, instead of comparing the length of the string, but more character Unicode. Encoded by the sequence, the greater the sequence: numbers (0-9), uppercase letters (AZ), lowercase letters (az)

 

 

Assignment Operators

Assignment operator is assigned a value of the operation based on the operand values ​​to its right to its left. The simplest assignment operator is equal to (=), the operation of the right value assigned to the left operand. Then x = y is the value of y is assigned to x.

Meaning: The data on the right side of the operation after the assignment to the left .

 

 

+ = Equal plus

- = subtraction is equal to

* = Multiplication equal

/ = Equal except

% = Equal modulo

++ sliding scale

- decreasing

On the basis of the original variables, calculates the right side, the calculation of the value assigned to the variable on the left again.

1	// 声明变量
2	var a = 10, b = 20, c = 30;
3	var sum = (a ++) + (++ b) + (c ++) + (++ a);
4	/*
5			= 10 + 21 + 30 + (++ a)   第二次出现就是再次使用,再次使用都是自加1后的结果
6			= 61 + 12
7			= 73
8	*/
9	console.log(sum);
10	console.log(a);
11	console.log(b);
12	console.log(c);
顺序:贴身的(! ++ --)→ 数学 → 比较 → 逻辑 → 赋值
1	/*
2	1优先级:  贴身,数学,比较(结果一定是布尔值),逻辑(与,或),赋值
3	2a++  :使用变量当前值参与运算,a第二次使用是自加1后的结果
4	3真:非0数字,非空字符串
5		a&&b:
6		a||b: 
7	*/
8	var a = 4;
9	var sum = 1 * (2 + 3) && a++ || 5 > 6 && 7 < 8 || 9;
10	/*
11			= 1 * (2 + 3) && 4 || 5 > 6 && 7 < 8 || 9;
12			= 5 && 4 || 5 > 6 && 7 < 8 || 9;  括号想加
13			= 5 && 4 || false && true || 9     数学比较
14			= 4 || false && true || 9         从左往右  a为真结果为b
15			= 4 || false || 9     a为假结果为假   与与或比较与优先级高
16			= 4 || 9      a或false  a为真结果为真
17			= 4      a为真结果为真

                           

18	*/
19	console.log(sum);
20	// 第二次出现a = 5
21	console.log(a);
22	console.log(++ a);

 

Guess you like

Origin blog.csdn.net/qq_41328247/article/details/88781889