js 类型基础知识

1 js数据类型

字符串:string

数组: number

布尔: boolean

对象: object  new Object(),{}

未定义: undefined undefined

原始类型:String、Number、Boolean、Null、Undefined

引用类型:Object、Function

2 typeof 返回值

typeof undefined || typeof jj || typeof ii || typeof ffy() 返回: "undefined" // jj未定义, var ii, ffy()无返回值

typeof false 返回:"boolean"

typeof "ff" 返回: "string"

typeof new Object() || typeof null || typeof new Boolean("ff") || typeof new Number("23") || typeof new String("ffx") || typeof new ffy() || typeof new Array(33) || typeof {} || typeof [33, 344] 返回:"object"

typeof 23 || typeof Number(23) 返回: "number"

typeof Function || typeof ffy 返回:  "function"

3 类型转换

0 、''、null 、undefined、false、[]、{}转换为false;  1 、new Object()、new Array()、Array转换为true。

4 等于true 或false

0 == [] == ''== false //因为3个值都是数值不存在

null == undefined

1 == true


猜你喜欢

转载自blog.csdn.net/menghu07/article/details/80280628