1. typeof操作符
typeof操作符可以用来判断变量的数据类型。
对于值类型有四种结果(undefined、string、number、boolean)
对于引用类型有两种结果(function、object)
注意:typeof null==object;
2, instanceof操作符
instanceof操作符用来判断引用类型。
语法:A instanceof B
判断规则:沿着A的_proto_属性这条线来找,同时沿着B的prototype属性这条线,若果两条线能找到同一个引用,即 同一个对象,则返回true。
instanceof表示的就是原型链的结构。。如下:
alert( Object instanceof Function) //true
alert(Function instanceof Object) //true
alert( Function instanceof Function) //true
图片来源:http://www.ibm.com/developerworks/cn/web/1306_jiangjj_jsinstanceof/figure1.jpg