JS Logical operator | | _javascript Tips

Source: Internet
Author: User
So query the introduction of JS:

1. Logic or operator | | :

When operator | | Of the two operands is a Boolean value that performs a Boolean or operation on both counts.

It first calculates the first operand, and if the value of the expression can be converted to true, it returns the value of the expression on the left. Otherwise, calculate the second shipment.

Even if | | The operator's operand is not a Boolean, and it can still be treated as a Boolean or operation, because it can be converted to a Boolean value regardless of the type of value it returns.

On the other hand, the number of operations for a non-boolean is used | |, which uses the attribute it returns to a value that is not Boolean. This use of this operator is typically to select the first defined and Non-null value in a set of alternative values (that is, the first value that is not converted to false)

Cases:

var Max=max_width | | Preferences.max_width | | 500

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.