前端
- html
- css
- js
html - 略
css - 略
js
- 数据结构
- 运算符
- 程序结构
- 函数
- 库
数据结构
- 原始值
- 引用值
原始值
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]'