JS中如何判定一个值为何种类型?

140 阅读1分钟
function verifyType(...target) {
  target.forEach((v, i) => {
    let type = Object.prototype.toString.call(v);
    console.log(`第${i + 1}个的type类型为${type.slice(8, -1)}`);
  });
}

测试


verifyType(1, "1", true, BigInt(19), undefined, {}, null, Symbol(1));

结果

QQ截图20220105152014.png