| 普通方式创建 | typeof | instanceof | new方式创建 | typeof | instanceof | |
| Object | var o={}; | object | Object | var o=new Object(); | object | Object |
| Array | var a=[]; | object | Array | var a=new Array(); | object | Array |
| Function | var f = function(){}; | function | Function | var f = new Function(); | function | Function |
| String | var s="hello,world"; | string | var s=new String("hello,world"); | object | String | |
| Number | var n =5; | number | var n =new Number(5); | object | Number | |
| Boolean | var b=true; | boolean | var b=new Boolean(true); | object | Boolean | |
| null | var nl= null; | object | ||||
| undefined | var un=undefined; | undefined | ||||
| *1."typeof operator returns a string indicating the type of the unevaluated operand." ---from MDC | ||||||
| *2."obj instanceof ConstructorFunction works by checking if ConstructorFunction.prototype is in the prototype chain of obj. "----from MDC | ||||||
typeof and instanceof
最新推荐文章于 2020-06-07 11:45:10 发布
本文详细介绍了JavaScript中使用typeof和instanceof进行类型检测的方法,并通过实例展示了不同内置对象(如Object、Array等)的创建方式及类型判断结果。
1527

被折叠的 条评论
为什么被折叠?



