判断一个变量的类型Object.prototype.toString.call

var num = 1;
alert(Object.prototype.toString.call(num)); // [object Number]
var str = 'hudidit.com';
alert(Object.prototype.toString.call(str)); // [object String]
var boo = true;
alert(Object.prototype.toString.call(boo)); // [object Boolean]
var fun = function(){};
alert(Object.prototype.toString.call(fun)); // [object Function]
var obj = {};
alert(Object.prototype.toString.call(obj)); // [object Object]
var arr = [];
alert(Object.prototype.toString.call(arr)); // [object Array]

var n = null;

alert(Object.prototype.toString.call(n)); //[object Null]

var u = undefined;

alert(Object.prototype.toString.call(u));//[object Undefined]

上一篇:[原创]java使用JDBC向MySQL数据库批次插入10W条数据测试效率


下一篇:Android Weekly Notes Issue #235