Logical operator &&| |! in JS __js

Source: Internet
Author: User
Tags logical operators numeric value

JS in the development of logical operators can be regarded as a more common operator, there are mainly three: logic and &&, logic or | | And logic is not.

When && and | | When a connection statement is made, the statements on both sides are converted to a Boolean type (Boolean), which is then performed, with the following operational rules:

1.&&

1.1 The result is true when both sides of the condition are true;

1.2 If one is false, the result is false;

1.3 When the first condition is false, the following condition is no longer judged

Note: When the numeric value participates in the logic and operation, the result is true, then the second is true, and if the result is false, the return is the first false value.

2.| |

2.1 If only one condition is true, the result is true;

2.2 The result is false when all two conditions are false;

2.3 When a condition is true, the following condition is no longer judged

Note: When a numeric value participates in a logic or operation, the result is true, the first true value is returned, and the second false value is returned if the result is false;

3..

3.1 The result is true when the condition is false, or vice versa.

Code description on:


<! DOCTYPE html>


Complementary: Logic and priority is higher than logic or;

Like Console.log (3| | 2&&5| | 0), will first calculate 2&&5 value is 5, then 3| | 5----3, finally again 3| | 0----3, so the final result is 3.

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.