Home >Web Front-end >JS Tutorial >Introduction to Boolean type analysis based on JavaScript data types_Basic knowledge

Introduction to Boolean type analysis based on JavaScript data types_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 17:36:101599browse

clip_image002

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:

Copy code The code is as follows:

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