1. <script>
    2. function Person(name,age){
    3. this.name = name;
    4. this.age = age;
    5. }
    6. var p = new Person("张三",18);
    7. var p1 = p;
    8. p1.name = "李四";
    9. console.log(p);
    10. console.log(p1);
    11. </script>

    image.png

    1. <script>
    2. var num = 10;
    3. var num1 = num;
    4. num = 20;
    5. console.log(num); //20
    6. console.log(num1); //10
    7. </script>
    1. <script>
    2. //全局变量
    3. var num = 10;
    4. function f1(){
    5. //局部变量 函数里面是可以声明和全局变量同名的变量,一旦声明之后,函数里面用的就是自己的
    6. var num = 60;
    7. console.log(num);
    8. }
    9. f1();
    10. console.log(num);
    11. </script>

    image.png

    1. <script>
    2. //全局变量
    3. var num = 10;
    4. function f1(num){
    5. //函数中的参数其实函数内部的信息
    6. num = 60; //这里面修改的仅仅只是自己的num,而不是全局变量
    7. console.log(num);
    8. }
    9. f1(num);
    10. console.log(num);
    11. </script>

    image.png

    1. <script>
    2. var num1 = 55;
    3. var num2 = 66;
    4. function f1(num,num1){
    5. num = 100;
    6. num1 = 100;
    7. num2 = 100;
    8. }
    9. f1(num1, num2);
    10. console.log(num1); //55
    11. console.log(num2); //100
    12. console.log(num); //not defined
    13. </script>

    image.png