【JavaScript】检测数据类型函数

//安全检测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));

【JavaScript】检测数据类型函数

 

上一篇:Java机试题*:字符串通配符(根据题目指定字符以及对应的通配要求处理,超时情况处理)


下一篇:python day04