前端知识架构

前端

  1. html
  2. css
  3. js

html - 略

css - 略

js

  1. 数据结构
  2. 运算符
  3. 程序结构
  4. 函数

数据结构

  1. 原始值
  2. 引用值

原始值
null
undefined
number/NaN
boolean
string
bigint(新)
symbol(新)

引用值
object
arrary
function
date
reg

typeof原始值

// 传统的原始值
typeof null == 'object'
typeof undefined == 'undefined'
typeof 123 == 'number'
typeof NaN == 'number'
typeof true == 'boolean'
typeof 'abc' == 'string'
// 新版本增加的两个原始值
typeof 10n == 'bigint'
typeof Symbol (Date) == 'symbol'

typeof引用值

typeof {} == 'object'
typeof [] == 'object'
typeof function () {} == 'function'
typeof Date == 'function'
typeof Date () == 'string'
Date () == 'Tue Mar 15 2022 18:33:41 GMT+0800 (中国标准时间)'
typeof RegExp == 'function'
typeof RegExp () == 'object'

接下来用Object.prototype.toString.call,再试一遍
原始值

Object.prototype.toString.call (null) == '[object Null]'
Object.prototype.toString.call (undefined) == '[object Undefined]'
Object.prototype.toString.call (123) == '[object Number]'
Object.prototype.toString.call (NaN) == '[object Number]'
Object.prototype.toString.call (true) == '[object Boolean]'
Object.prototype.toString.call ('abc') == '[object String]'
// 新增的原始值
Object.prototype.toString.call (10n) == '[object BigInt]'
Object.prototype.toString.call (Symbol (Date) == '[object Symbol]'

引用值

Object.prototype.toString.call ({}) == '[object Object]'
Object.prototype.toString.call ([]) == '[object Array]'
Object.prototype.toString.call (function () {}) == '[object Function]'
Object.prototype.toString.call (Date) == '[object Function]'
Object.prototype.toString.call (Date ()) == '[object String]'
Object.prototype.toString.call (RegExp) == '[object Function]'
Object.prototype.toString.call (RegExp ()) == '[object RegExp]'

记住,typeof name == ‘string’,因为name本身在window上是有值的,所以并不会typeof name == undefined

因为window上存在
name == ''
所以并不会显示undefined,所以
typeof name == 'string'
Object.prototype.toString.call (name) == '[object String]'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值