typeof
typeof 一般只能返回如下几个结果:“number”、“string”、“boolean”、“undefined”、“object” 和 “function” 。
对于原始类型来说,除了 null 都可以显示正确的类型。(因为 null 代表的是空对象)
对于对象来说,除了函数都会显示 object。
instanceof
instanceof 运算符用来测试一个对象在其原型链中是否存在一个构造函数的 prototype 属性。
注意:
var str = 'hello world'
str instanceof String // false
var str1 = new String('hello world')
str1 instanceof String // true
原因:
str='hello'
//返回值:"hello"
str1=new String('hello')
//返回值:String {"hello"}