1.原始类型的值传递
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
var a = 10;
var b = a;
a = 20;
console.log(a,b);
</script>
</body>
</html>
运行结果:20 10
引用类型值传递
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
/* var a = 10;
var b = a;
a = 20;
console.log(a,b);*/
var arr = [1,2,3,4,56,7,78];
var arr1 =arr;
arr[0] = "hello";
console.log(arr,arr1);
</script>
</body>
</html>
运行结果:(7) ["hello", 2, 3, 4, 56, 7, 78] (7) ["hello", 2, 3, 4, 56, 7, 78]
在引用类型中变量保存的是一个地址,传值时将这个地址传递出去,当一处修改值时就会修改所有引用此地址变量的值