JS Non-Boolean operation logic and logic or *

Source: Internet
Author: User

/*js Non-Boolean operation logic and logic or */
/*
* Note: ("", 0, undefined, NaN, null converted to false)
* */
/* Logic and */
Console.log ((1 && 1 && "Hello" && 2 && 3 && 4));//First conversion to True returns last A value (4)
Console.log ((0 && 0 && "Hello" && 2 && 3 && 4));//First conversion to False returns the first value (0)
Console.log ((1 && 2 && 3 && null && nan));//The action value has a null NaN undefined one of them returns this value (with more than one of the top) Returns null

/* Logic or */
Console.log ((1 | | | 1 | | "Hello" | | 2 | | 3 | | 4)); First conversion to true returns the first value (1)
Console.log ((0 | | | 0 | | "Hello" | | 2 | | 3 | | 4)); The first conversion to false returns the first value converted to True (hello)
Console.log ((0 | | | 0 | | "" || Undefined | | NaN | | NULL)); Convert all to False returns the last (null)

JS Non-Boolean operation logic and logic or *

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.