<script>
//getType方法
let getType = data => Object.prototype.toString.call(data);
//测试数据
let a,
b = null,
c = true,
d = 10,
e = '',
f = {},
g = [],
h = new Date(),
i = new RegExp('', 'gi'),
j = function () {},
k = Symbol(''),
l = BigInt(0),
m = class {};
//输出
console.log('a is', getType(a));//Undefined
console.log('b is', getType(b));//Null
console.log('c is', getType(c));//Boolean
console.log('d is', getType(d));//Number
console.log('e is', getType(e));//String
console.log('f is', getType(f));//Object
console.log('g is', getType(g));//Array
console.log('h is', getType(h));//Date
console.log('i is', getType(i));//RegExp
console.log('j is', getType(j));//Function
console.log('k is', getType(k));//Symbol
console.log('l is', getType(l));//BigInt
console.log('m is', getType(m));//Function,类是函数的语法糖,因此判断出来的是Function类型的数据
</script>
最后修改:2022 年 03 月 29 日 03 : 54 PM
© 允许规范转载