标签:
在编写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