Home  >  Article  >  Web Front-end  >  What are the rules for converting JS type values ​​into Boolean types?

What are the rules for converting JS type values ​​into Boolean types?

php中世界最好的语言
php中世界最好的语言Original
2018-03-19 16:25:462850browse

This time I will bring you the rules for converting JS type values ​​into Boolean types, and what are the precautions for converting JS type values ​​into Boolean types. The following is a practical case, let’s take a look. one time.

Due to the recent written examination, I found a lot of questions about converting other types into Boolean types, so I will summarize it!

1. Convert the

String type to Boolean

1. When the result of conversion j is true

①Any non-empty

string

PS: Blank strings also return true

2. When the conversion result is false

①Empty string

##2. Convert Number type to Boolean

1. When the conversion result is true

①Any non-0 numeric value (including infinity)

2. When the conversion result is false

①0

②NaN

3.

Object class

type is converted to Boolean1. The conversion result is true Situation

①Any object (including empty objects)

②Array object (including empty arrays)

Regular expression

2. When the conversion result is false

①Empty object

PS: This should be distinguished from the previous empty object {}. An empty object means that the object has been created, but there is nothing in it, while an empty object means that it has not been created, which is a null

4. Convert Undefined type to Boolean

1. Can only return false

I believe I read this article You have mastered the case method. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

How to use JavaScript strings


How to implement two-way data binding in WeChat applet

The above is the detailed content of What are the rules for converting JS type values ​​into Boolean types?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn