//安全检测Js基本数据类型和内置对象 function typeOf(o) { let _toString = Object.prototype.toString(); let _type = { "undefined": "undefined", "number": "number", "boolean": "boolean", "string": "string", "[object Function]": "function", "[object RegExp]": "regexp", "[object Array]": "array", "[object Date]": "date", "[object Error]": "error" } return _type[typeof o] || _type[_toString.call(o)] || (o ? "object" : "null"); } let a = Math.abs(); document.write(typeOf(a));