Home > Web Front-end > JS Tutorial > body text

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

php中世界最好的语言
Release: 2018-03-19 16:25:46
Original
2730 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!