一.基本数据的内存模型
在js中基本数据类型有5种:number、string、boolean、Undefined、null。可以通过“typeof 变量”来查看变量属于什么类型。
其中Number类型:整数 、浮点数
String类型:字符串,字符
boolean:true、false
Undefined:未定义的变量,即没有使用var 或const声明的变量
null:变量没有赋值,即声明了这个变量,但没有给这个变量赋值。
这些基本数据都是直接赋值给变量。
内存模型:
var a=123;
放在栈中:a:123
二.引用数据内存模型
在js中引用对象有几种方式:
1.var people={
name:"李四"
age:32;
getName:function(){
return this.name;
}
}
内存模型:栈空间: people:abc123 堆空间:abc123:name:"李四"
age:32
getName:f()
_proto_:Object
2.function People(name,age){
this,name=name;
this.age=age;
this,getName=function(){
、 return name;
}
}
var p1=new People("李四",”21“)
内存模型:栈空间: p1:abc123 堆空间:abc123: name:李四
age:32
getName:f()
_proto_:Object