Tag: console var resolves als priority logic priority STR FALSE
First, && (logic and) operations, see a simple example:
var a = 1 && 2 && 3;
var b = 0 && 1 && 2;
var c = 1 && 0 && 2;
Console.log (a);//value is 3
Console.log (b);//value is 0
Console.log (c);//value is 0
The result of the operation is: 3,0,0.
Analytical:
The "&&" operation returns when it encounters false;
Calculation of variable A: Because 1 && 2,1 is true, returns 2;2&&3, 2 is true, and returns 3.
Calculation of variable B: Because 0 && 1,0 is False, returns 0, no longer calculates downward.
Second, | | (logical OR) operation, see a simple example:
var d = 0 | | 1 | | 2;
var e = 1 | | 0 | | 2;
var f = 1 | | 2 | | 0;
Console.log (d);//value is 1
Console.log (e);//value is 1
Console.log (f);//value is 1
Analytical:
"| |" The operation returns when it encounters true;
Calculation of the variable D: since 0 | | 1,0 is False, return 1;1 | | 2, 1 is true, returns 1.
Calculation of the variable e: since 1 | | 0,1 is true and returns 1, no longer counting down.
Iii. && (Logic and) and | | (logical OR) mixed use:
var g = 1 && 2 | | 3;
var h = 1 | | 2 && 3;
var i = 0 | | 2 && 3;
Console.log (g);//value is 2
Console.log (h);//value is 1
Console.log (h);//value is 3
Analytical:
&& (logical AND) priority is higher than | | (logical OR);
Calculation of the variable g: since 1 && 2,1 is true, return to 2;2 | | 3, 2 is True, returns 2.
Calculation of the variable e: Equation as 1 | | (a value), 1 is true, and finally returns 1 directly, without the need to calculate the value of the equation behind it.
Calculation of the variable I: Since 2 && 3,2 is true, return to 3;0 | | 3,0 is False and returns 3.
[Go] js operator && | | and its priority