Use the special features of the operators "|" and "&" in JScript to simplify code _ javascript skills

Source: Internet
Author: User
The special features of the operators & quot; | & quot; and & quot; & amp; & quot; in JScript are used to simplify the code into many operators in JScript, three logical operators are provided. &&, |And !Oh ?! Is provided in advanced languages. According to our normal understanding of logical operations, the logical operation result should be true or false. However, the logic operations of JScript are not exactly defined in this way. only! The true | false operator is always returned, and | is more fun.

JScript defines true or false for logical operations as follows:

  • All objects are considered true.

  • String is considered as false only when it is null ("" or.

  • NullAnd undefined are regarded as false.

  • The value is false only when the value is 0.

But logical operators|And&&Although the above defined rules are followed, the returned values are very interesting.
For & Operations, according to the above rules, if ('ABC' & '000000' & new Date () is the true branch, but this expression is written as follows:

I tested it in Firefox and the results are the same!

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.