Skip to content

Latest commit

 

History

History
16 lines (11 loc) · 551 Bytes

#50-实现js数据类型的判断.md

File metadata and controls

16 lines (11 loc) · 551 Bytes

题目描述:

最新的 Javascript 标准规定了六种基本数据类型(number, null, undefined, string, boolean, symbol) 和基于 Object 衍生的其它原生数据类型,写出 type 函数,它传入一个参数,返回它的数据类型(用小写字母),比如: type(new Date),返回 date


参考答案:

const type = (obj) => {
  return Object.prototype.toString.call(obj).slice(8, -1).toLowerCase();
}