基本数据类型
基本数据类型有 null,undefined,String,Boolean,Number,Bigint,Symbol 7 种
基本数据类型的特点
- 创建和存储:从常量池中取出值放在栈内存的暂存区
- 复制: 复制的是暂存区中常量的地址
所以有:
let a = 'abc'
let b = a
a === b //true
a = 'abcd'
b //'abc'
销毁:栈内存中的分配和销毁都由操作系统操作,在分配栈内存时如果所剩空间小于所申请的内存,会报 栈内存溢出 stack overflow
Undefined
声明了一个变量,但没有进行初始化的时候,这个变量为undefined
let a
undefined
一般 不做 let a = undefined 这种无意义的显示的操作
NULL
声明了一个变量,但是值暂时为空
let a = null
用于声明一个变量,并表明这个变量为空的意思。所以 typeof null == ‘object’
typeof null // "object" (not "null" for legacy reasons)
typeof undefined // "undefined"
null === undefined // false
null == undefined // true
null === null // true
null == null // true
!null // true
isNaN(1 + null) // false
isNaN(1 + undefined) // true
BigInt
引用数据类型
引用数据类型有 Object ,Array,Function
引用数据类型的特点
创建:通过new 或者字面量的形式创建,非系统自动分配内存
- 存储:存储在堆内存中
-
基本数据类型
Date 和 RegExp 等ECMAScript 提供的原 生引用类型
-
函数 function
单例内置对象
Global 对象在浏览器中被实现为 window 对象。所有全局变量和函数都是 Global 对象的属性
-
集合引用类型
最常见的 Object 和 Array
- Map、WeakMap、Set 以及 WeakSet 类型
- 定型数组:例如 Int32Array、Float64Array 等等