#数据类型
最常见的判断方法:typeof
1 | // 可以区分基本类型和undefined |
判断已知对象类型的方法: instanceof
- null的typeof为object,function和undefined可以使用typeof
1 | # 可以区分object和array分别是哪个构造函数的实例 |
prototype
1 | alert(Object.prototype.toString.call(‘123’) === ‘[object String]’) -------> true; |
##基本类型
String
typeof // “string”
Number
typeof // ‘number’
Boolean
typeof boolean // ‘boolean’
特殊类型
null
typeof // 注意是‘object’
undefined
typeof // ‘undefined’
function
function test(){}
typeof test // ‘function’
##变态类型
object
typeof // object
instantceof Object // true
function
typeof // function
instance of Function // true
array
typeof //object
instance of Array // true