js的instanceof跟typeof

js的instanceof和typeof? ? Js中的instanceof和typeof两个经常会搞混,现在就来分析下:? ? 1.?instanceof?

js的instanceof和typeof

? ? Js中的instanceof和typeof两个经常会搞混,现在就来分析下:

? ? 1.?instanceof

? ? 返回一个Boolean值,指出对象是否是特定类的一个实例。

?

var s = new String("abc");console.log(typeof s == "string"); //falsevar s = "abc";console.log(typeof s == "string");  //true
? ? 总结:在对象之间比较时,使用instanceof;在基本类型之间比较时使用typeof

?