&& and | | In the jquery source code is particularly widely used, because I do not have the system to learn JS, so only a cursory understanding of the self, I hope we can guide.
A rough understanding is as follows:
A () && B (): If True after a () is executed, B () is executed and the value of B is returned, and if A () is returned false, the entire expression returns the value of a (), and B () is not executed;
A () | | B (): If True after a () is executed, the entire expression returns the value of a (), B () is not performed, and if A () is returned false, B () is executed and the value of B () is returned;
&& priority is higher than | |
As follows:
Code
Copy Code code as follows:
Alert ((1 && 3 | | 0) && 4); Results 4①
Alert (1 && 3 | | 0 && 4); Results 3 ②
Alert (0 && 3 | | 1 && 4); Results 4③
Analysis:
Statement ①:1&&3 return 3 => 3 | | 0 Return 3 => 3&&4 return 4
Statement ②: First executes 1&&3 return 3, returns 0 in execution 0&&4, finally executes the result comparison 3| | 0 Return 3
Statement ③: First executes 0&&3 return 0, returns 4 in execution 1&&4, finally executes the result comparison 0| | 4 return 4
Note: Integers other than 0 are true,undefined, NULL, and null string "" to false.