JavaScript 数据类型判断

typeof

typeof 一般只能返回如下几个结果:"number"、"string"、"boolean"、"object"、"function" 和 "undefined"。

instanceof

instanceof 运算符用来检测 constructor.prototype 是否存在于参数 object 的原型链上。

var o = new C();
o instanceof C; // true,因为 Object.getPrototypeOf(o) === C.prototype

js数据类型判断(Object.prototype.toString.call)

// Object.prototype.toString.call

Object.prototype.toString.call('aaaa')        输出      [object String]
Object.prototype.toString.call(2222)         输出      [object Number]
Object.prototype.toString.call(true)          输出      [object Boolean]
Object.prototype.toString.call(undefined)  输出      [object Undefined]
Object.prototype.toString.call(null)                  输出   [object Null]
Object.prototype.toString.call({})                   输出   [object Object]
Object.prototype.toString.call([])                    输出   [object Array]
Object.prototype.toString.call(function(){})     输出   [object Function]

results for ""

    No results matching ""