Home >Web Front-end >JS Tutorial >Introduction to Boolean type analysis based on JavaScript data types_Basic knowledge
Today we are talking about a Boolean type among data types, which returns two literal values of true and false. It should be noted that literal values are case-sensitive, that is, except for lowercase, everything else is just an identifier.
The following mainly talks about various data types and corresponding conversion rules:
Data type Value converted to true Value converted to false
-------------------------------------------------- ----------------------------------
Boolean true true
String Any non-empty string ""(empty string)
Number Any non-zero numeric value 0 and Nan
Object Any object null
Undefined Not applicable
-------------------------------------------------- ----------------------------------
These conversion rules are very important for understanding flow control statements (such as if statements) and automatically performing corresponding Boolean conversions. Please see the following code: