1. 首页
  2. 数据库
  3. 其它
  4. typeof、instanceof、constructor 的联系、区别、应用场景(js 类型判断)

typeof、instanceof、constructor 的联系、区别、应用场景(js 类型判断)

上传者: 2021-01-16 20:49:11上传 PDF文件 95.76KB 热度 41次
联系 这三者都可以用来判断一个对象的类型 let now = new Date() now instanceof Date // 输出: true now.constructor == Date // 输出: true typeof 'hello' // 输出: string typeof('hello') // 高版本的 js 支持这种写法。输出: string 看起来是这样的: typeof 返回一个对象的类型的名字,即返回一个字符串 instanceof 用来判断左边的值是否属于右边的类型,返回布尔值 true 或 false(严谨地说是:“左值是否为右值的实例”) construct
下载地址
用户评论