js 判断数据类型、检测变量类型、对象的类型(typeof)
分享知识http://www.fedrobots.com/?search=188498我来纠错//typeof,返回变量类型
typeof(1); //返回:"number"
typeof(NaN); //返回:"number"
typeof(Number.MIN_VALUE); //返回:"number"
typeof(Infinity); //返回:"number"
typeof("123"); //返回:"string"
typeof(true); //返回:"boolean"
typeof([1,2,3]); //返回:"object"
typeof([]); //返回:"object"
typeof({"a":1,"b":2}); //返回:"object"
typeof(window); //返回:"object"
typeof(document); //返回:"object"
typeof(null); //返回:"object"
typeof(eval); //返回:"function"
typeof(Date); //返回:"function"
typeof(sss); //返回:"undefined"
typeof(undefined); //返回:"undefined"
//实例
var test = function(){ var a=1; };
if(typeof test == 'function'){
alert('这是一个function类型');
}