码迷,mamicode.com
首页 > 其他好文 > 详细

typeof和instanceof

时间:2017-12-08 18:30:16      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:func   string   style   cti   instance   boolean   ring   nbsp   back   

js用来判断数据类型的方法有2种:typeof和instanceof,一般typeof就够用

1.typeof

typeof ‘123‘ //"string"

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

 

2.instanceof

new Date() instanceof Array //false
new Date() instanceof Date //true

instanceof就是用于判断一个对象是否是哪个类

typeof和instanceof

标签:func   string   style   cti   instance   boolean   ring   nbsp   back   

原文地址:http://www.cnblogs.com/amiezhang/p/8006442.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!