Skip to content
字数
210 字
阅读时间
1 分钟

1. 值类型和引用类型

  1. 值类型不会改变,引用类型会改变
  2. 引用类型:
js
let a = {name:'alex',age:20}

let b = a;

b.age = 21;

console.log(a.age);//21

值类型


| 栈   | 栈     | 栈   | 栈     | 栈   | 栈     |
| --- | ----- | --- | ----- | --- | ----- |
| key | value | key | value | key | value |
| a   | 100   | a   | 100   | a   | 200   |
|     |       | b   | 100   | b   | 100   |
|     |       |     |       |     |       |

引用类型

|栈|栈|栈|栈|栈|栈|
|---|---|---|---|---|---|
|key|value|key|value|key|value|
|a|内存地址1|a|内存地址1|a|内存地址1|
| | |b|内存地址2|b|内存地址2|
| \n  | | | | | |
| \n| | | | | |
|内存地址1|{age:20}|内存地址1|{age:20}|内存地址1|{age:21}|
|key|value|key|value|key|value|
|堆|堆|堆|堆|堆|堆|

何时用==何时用===

只有判断 if(object.a null){} 时,用 “==”, 相当于 if(object.a = null || object.a === undefined){} 其他时候一律用“ === ”

贡献者

The avatar of contributor named as sunchengzhi sunchengzhi

文件历史

撰写