0
点赞
收藏
分享

微信扫一扫

判断数据类型

烟中雯城 2021-09-23 阅读 117
面试题
  1. intanceof
    用法:object intanceof constructor
    intanceof 运算符用来检测 constructor.prototype 是否存在于参数 object 的原型链上
    object : 某个实例对象
    constructor:某个构造函数

作用:检测 object 是否为 constructor的实例
例如:arr intanceof Array

  1. typeof
    typeof 操作符返回一个字符串,表示未经计算的操作数的类型

3.Object.prototype.toString.call(要判断的)
typeof 无法区分对象、数组、函数的类型;
可以通过 Object.prototype.toString方法,判断某个对象属于哪种内置类型。
分为null,string、boolean、number、undefined、array、function、object、date、math

举报

相关推荐

0 条评论