js数据类型:
1、基本(值)类型:
String:任意字符串
Number:任意数值
boolean: True False
undefined: undefined
null: null
2、 对象(引用)类型 :
Object: 任意对象
Function: 一种特殊对象(可以执行)
Array: 一种特殊对象(数值下标,有序的)
数据类型判断:
typeof: 返回的结果是变量的数据类型字符串('undefined' 'string' 'number' 'object' 'boolean' 'function')
instanceof: 用于对象类型 判断对象具体类型
===: undefined null
var a ;
console.log(a, typeof a, a === undefined, typeof a === 'undefined') // undefined 'undefined' true true
a=4
console.log( typeof a === 'number') //true
a='www'
console.log( typeof a === 'string') //true
a=null
console.log( typeof a, a===null) //'object' true
var b1= {
b2: [1,'abc',console.log],
b3: function() {
console.log('b3')
}
}
console.log(b1 instanceof Object, b1 instanceof Array) // true false
console.log(b1.b2 instanceof Object, b1.b2 instanceof Array) // true false
console.log(b1.b3 instanceof Object, b1.b3 instanceof Function) // true true