SOURCE

// 复制基本类型
var num1 = 5;
var num2 = num1;
console.log('num1 is ',num1);
console.log('num2 is ',num2);
num2 = 10;
console.log('now num1 is ',num1);
console.log('now num2 is ',num2);

// 引用类型
var obj1 = new Object();
var obj2 = obj1;
obj1.name = 'Nicholas';
console.log('obj2\'s name is ',obj2.name);

//所有参数都是按值传递的

// 基本类型的传递无差别
function addTen(num){
  num += 10;
  return num;
}
var count = 20;
var result = addTen(count);
console.log(count);
console.log(result);

// 引用类型的传递
function setName(obj){
  obj.name = 'Nicholas';
}
var person = new Object();
setName(person);
console.log(person.name);

// 但是对象也是按值传递的哦
function setName2(obj){
  obj.name = 'Nicholas';
	// 这个局部对象在函数执行完毕后会立即被销毁
  obj = new Object();
  obj.name = "Greg";
}
var person = new Object();
setName(person);
console.log(persona.name);
console 命令行工具 X clear

                    
>
console