JavaScript类型检测

时间:2015-05-27 22:29:32   收藏:0   阅读:293

     在编写JS代码中,经常要对某个变量进行类型检测。常用的类型检测方法有:

typeof

typeof可以识别出基本数据类型(null除外),同时typeof并不能识别具体的对象类型(Function除外).

eg:   

typeof "seven";     // "string"
typeof 7;     //"number"
typeof true ;     // "boolean"
typeof undefined;  // "undefined"
typeof null   ;       // "object"    
typeof {name:"seven"};   //"object"
typeof function(){};    //"function"
typeof [] ;    //"object"
typeof new Date;   //"object"
typeof /\w/ ;    // "object"
function Student(){};
typeof   new Student(); //"object"

  

 

原文:http://www.cnblogs.com/seven-zh/p/4534430.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!