JS other type value converted to a Boolean type rule

Source: Internet
Author: User

As recently as in the written test, found a lot of other types of conversion to a Boolean type of topics, so summarize!

First, the string type is converted to Boolean1. The case that the conversion J result is true

① any non-empty string

PS: Blank string also returns True

2. Case where the conversion result is false

① empty string

Second, the number type is converted to Boolean1. case where the conversion result is true

① any non-0 numeric value (including infinity)

2. Case where the conversion result is false

①0

②nan

Iii. the type of object is converted to Boolean1. case where the conversion result is true

① any object (including empty objects)

② array objects (including empty arrays)

③ Regular Expressions

2. Case where the conversion result is false

① Empty objects

PS: Here to distinguish with the previous empty object {}, an empty object indicates that the object was created, but there is nothing in it, and the empty object represents the creation, which is a null

Iv. undefined type converted to Boolean1. can only return false

JS other type value converted to a Boolean type rule

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.