& | In jquery Source codeBecause I do not have a system to learn JS, I can only make a rough understanding of myself. I hope you can give me some advice.
A rough understanding is as follows:
A () & B (): If true is returned after a () is executed, B () is executed and the value of B is returned. If false is returned after a () is executed, then the entire expression returns the value of A (), and B () is not executed;
A () | B (): If true is returned after a () is executed, the entire expression returns the value of A (). B () is not executed. If a () is executed () if false is returned, B () is executed and the value of B () is returned;
& The priority is higher than |
As follows:
Code Copy codeThe Code is as follows: Alert (1 & 3 | 0) & 4); // Result 4 ①
Alert (1 & 3 | 0 & 4); // result 3 ②
Alert (0 & 3 | 1 & 4); // Result 4 ③
Analysis:
Statement ①: 1 & 3 returns 3 => 3 | 0 returns 3 => 3 & 4 returns 4
Statement ②: Execute 1 & 3 first, return 3, return 0 in execution 0 & 4, and finally compare 3 | 0 returns 3
Statement ③: Execute 0 & 3 first, return 0, return 4 in execution 1 & 4, and finally compare 0 | 4 returns 4
Note: All integers other than 0 are true, and undefined, null, and null strings "" are false.