function classOf(x){ if(x === null) return "NULL"; if(x === undefined) return undefined; return Object.prototype.toString.call(x).slice(8,-1); } var x = 13; console.log(classOf(x));
JS小tips 之 toString返回变量类型
原文:http://www.cnblogs.com/ideal-idiot/p/7813126.html