first, to say that | | (logical or), which, literally, returns false only when both the front and back are false, otherwise it returns True.
Alert (true| | false); True
Alert (false| | true); True
Alert (true| | true); True
Alert (false| | false); False
but, in the deep sense, there is another world, try the following code
Alert (0| | 1);
obviously, we know that the previous 0 means false, and the next 1 means true, then the result above should be true, and the result of the fact returned is 1. Then look at the following code:
Alert (2| | 1);
We know that the previous 2 is true, and the back 1 is also true, so what is the return result? The test result is 2, continue to look:
Alert (' a ' | | 1);
again, the front ' a ' is true, the back 1 is also true; the test result is ' a ', below
Alert (' | | | 1);
From the top, we know that the front "is false, the back 1 is true, and the return result is 1." Look at the bottom again.
Alert (' a ' | | 0);
The front ' a ' is true, and the back 0 is false, and the result is ' a ', continue below
Alert (' a ' | | ' b ');
The front ' a ' is true, the back ' B ' is false and the return result is ' a ', we continue below
Alert (' | | | 0);
The front "is false, and the back 0 is also false, and the result is 0
Alert (0| | ");
The previous 0 is false, the back "is false, and the return result is '
This means
1, as long as "| |" False in front, regardless of "| |" Followed by true or false, return "| |" The value that Follows.
2, as long as "| |" Preceded by true, regardless of "| |" Followed by true or false, return "| |" The preceding Value.
Let's summarize:
1, as long as "| |" False before, regardless of ' | | ' Followed by true or false, the result returns "| |" The value that Follows.
2, as long as "| |" Preceded by true, regardless of "| |" Followed by true or false, the result returns "| |" The preceding Value.
3, as long as "&&" is false, whether "&&" followed by true or false, the result will be "&&" the preceding value;
4, as long as "&&" is true, whether "&&" followed by true or false, the result will be returned to "&&" the value after;
From the last two tests, the logical operator, "| |" And "&&" are to follow the short-circuit principle, as long as the symbol before the true and false, can determine the return Value.
It should be stated that the priority of "&&" is higher than "| |" , the following tests:
Alert (1| | ' A ' &&2);
The return result is 1.
Based on the principle of absurdity, we assume that "| |" The priority level is not less than "&&" (here only so "no less" is to prove the same level of the same situation).
According to the conclusions we have drawn above (1), (1| | ' A ') will return the previous value 1, (1&&2) according to the conclusion (4) should return the following value 2. This is obviously not true, so the priority of "&&" is higher than "| |" Of
JS operator && | | Usage of