javascript数据类型

js七种内置类型:

1.空值(null)

2.未定义(undefined)

3.布尔值(boolean)

4.数值(number)

5.字符串(string)

6.对象(object)

7.符号(symbol)

除对象之外,其他对象统称为 "基本类型"

typeof运算符来查看值的类型返回的是类型的字符串值

typeof undefined === "undefined"  //true

typeof true === "boolean"             //true

typeof 43 === "number"               //true

typeof "43" === "string"              //true

typeof Symbol === "symbol"        //true

typeof NaN                                //number

typeof NaN === "number"          //true

null 是falsy(假值)是唯一一个用typeof检测返回object的值

 

类型转换

!!String(" ")      //返回 true                 !!String([])    //false             !!String(0)   //true

!!Boolean(" ")   //返回 false                 !!Boolean([])  //true               !!Boolean(0) //false

!!Number(" ")   //true                         !!Number([])  //false             !!Number(0) //false

数据类型 转换为true的时候 转换为false 的时候
Boolean   true false
    String 任何非空字符 空字符串" "
Number 任何非零数值(包括无穷大) 0和NaN
Object 任何对象 null
Undefined - undefined
如有不足的地方欢迎指正,谢谢诸位大神啦
原文地址:https://www.cnblogs.com/menghan94/p/12157216.html