基本数据类型

基本数据类型有 null,undefined,String,Boolean,Number,Bigint,Symbol 7 种

基本数据类型的特点

  • 创建和存储:从常量池中取出值放在栈内存的暂存区
  • 复制: 复制的是暂存区中常量的地址

所以有:

  1. let a = 'abc'
  2. let b = a
  3. a === b //true
  4. a = 'abcd'
  5. b //'abc'
  • 销毁:栈内存中的分配和销毁都由操作系统操作,在分配栈内存时如果所剩空间小于所申请的内存,会报 栈内存溢出 stack overflow

    Undefined

    声明了一个变量,但没有进行初始化的时候,这个变量为undefined

    1. let a
    2. undefined

    一般 不做 let a = undefined 这种无意义的显示的操作

    NULL

    声明了一个变量,但是值暂时为空

    1. let a = null

    用于声明一个变量,并表明这个变量为空的意思。所以 typeof null == ‘object’

    1. typeof null // "object" (not "null" for legacy reasons)
    2. typeof undefined // "undefined"
    3. null === undefined // false
    4. null == undefined // true
    5. null === null // true
    6. null == null // true
    7. !null // true
    8. isNaN(1 + null) // false
    9. isNaN(1 + undefined) // true

    BigInt

    引用数据类型

    引用数据类型有 Object ,Array,Function

    引用数据类型的特点

  • 创建:通过new 或者字面量的形式创建,非系统自动分配内存

  • 存储:存储在堆内存中
  • 销毁:由js解析引擎内置的垃圾回收机制回收

    基本数据类型

  • Date 和 RegExp 等ECMAScript 提供的原 生引用类型

  • 包装数据类型 Boolean,String,Number

    函数 function

    单例内置对象

  • Global 对象在浏览器中被实现为 window 对象。所有全局变量和函数都是 Global 对象的属性

  • Math 对象包含辅助完成复杂计算的属性和方法

    集合引用类型

  • 最常见的 Object 和 Array

  • Map、WeakMap、Set 以及 WeakSet 类型
  • 定型数组:例如 Int32Array、Float64Array 等等

image.png