Home >Web Front-end >JS Tutorial >JavaScript data type Boolean type

JavaScript data type Boolean type

高洛峰
高洛峰Original
2016-11-28 13:35:471371browse

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" );
}

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