Home >Web Front-end >JS Tutorial >JavaScript data type Boolean type
Today we are talking about a Boolean type in the data type, which returns two literal values of true and false. It should be noted that the 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:
The data type is converted into a true value and converted into a false value
-------------------------- -------------------------------------------------- ----------------
Boolean true false
string Any non-empty string "" (empty string)
Any non-zero digital value 0 and nan
Object Any object null
Undefined Not applicable undefined
------------------------------------------------ --------------------------------------------------These conversions Rules are very important for understanding flow control statements (such as if statements) and automatically performing corresponding Boolean conversions. Please see the following code:
var msg="Hello World";
if(msg){ alert("Valus is true" );
}