基本类型

直接存储值

  • Number 、 String 、Boolean
  • undefined、null

引用类型

存储引用

-Object、Array、Date、函数

包装基本类型——引用类型

function Student(name,age,salary){
    this.name =name;
    this.age = age;
    this.salary =salary;
}
var s1 = new Student("zs",19,199);
var s2 = s1;
console.log(s2.name);

s1.name = "hkj";
console.log(s2.name);

//基本类型和复杂类型作为函数的参数

// 基本类型作为函数的参数
// 当基本类型作为函数的参数的时候,函数内部对参数的修改,不会修改外部的变量
function f1(a){
    a=100;
}
var x=1;
f1(x);
console.log(x); //1

//复杂类型作为函数的参数

function f2(stu){
    // var stu = new Student();
    stu.name="xxx";
}
var s= new Student("zs",18,100);
f2(s);
console.log(s.name); //xxx

相关文章:

  • 2022-02-01
  • 2022-12-23
  • 2021-12-06
  • 2021-07-13
  • 2021-06-21
  • 2021-09-14
猜你喜欢
  • 2022-12-23
  • 2021-10-31
  • 2021-08-18
  • 2021-07-10
  • 2021-05-21
  • 2022-01-23
相关资源
相似解决方案