JavaScript and | alternative use skills of the Algorithm

Source: Internet
Author: User

& | 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.