原始值和引用 值的栈和堆的存储原理
<script>
//原始值赋值
var aaa = 1;
var bbb = 2;
aaa = bbb;
//引用值赋值
var arr1 = [1,2];
var arr2 = arr1;
arr1 = [1,2,3,4]
</script>
变量名 | 编号(stack) | 栈(stack) | 编号(heap) | 堆(heap) | |
1001 | 1(原始值) | ||||
bbb | 1002 | 2(原始值) | |||
aaa | 1003 | 2(原始值) | |||
1004 | heap1004 | 1004 | [ 1, 2](引用值) | ||
arr2 | 1005 | heap1004 | 1005 | ||
arr1 | 1006 | heap1006 | 1006 | [1, 2, 3, 4](引用值) | |