Home  >  Article  >  Web Front-end  >  基于JavaScript 数据类型之Boolean类型分析介绍_基础知识

基于JavaScript 数据类型之Boolean类型分析介绍_基础知识

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

clip_image002

今天我们说的是数据类型中的一种Boolean类型,它返回true和false两个字面值,需要注意的是字面值是区分大小写的,也就是除了小写 其他的都只是标识符。

下面主要说的是各种数据类型以及对应的转化规则:

数据类型   转化为true的值   转化为false的值

--------------------------------------------------------------------------------
 

Boolean                true                                false

String       任何非空字符串        ""(空字符串)

Number      任何非零数字值        0和Nan

Object        任何对象            null

Undefined    不适用            undefined


--------------------------------------------------------------------------------

这些转化规则对理解流程控制语句(如if语句)自动执行相应的Boolean转化非常重要,请看下面的代码:

复制代码 代码如下:

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