Javascript logical Operators | _ javascript skills

Source: Internet
Author: User
The first time I saw such a statement aa | [], I still had some questions, because I have never seen such a statement in other languages. Query the introduction of js:

1. Logic or operator |:

When the operator | is a Boolean value, it performs a Boolean OR operation on the two operators.

It calculates the first operation number first. If the value of this expression can be converted to true, it returns the value of the expression on the left. Otherwise, calculate the second operation.

Even if | the operator's number of operations is not a Boolean value, it can be considered a Boolean OR operation, because whatever type of value it returns can be converted to a Boolean value.

On the other hand, we use | for non-Boolean operations, which uses the features that will be returned by non-boolean values. This operation usually selects the first defined and non-null value in a set of optional values (that is, the first value will not be converted to false)

Example:

Var max = max_width | preferences. max_width || 500
Related Article

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.