// 按值传递参数:基本数据类型的参数从函数外传递到函数内并进行操作,函数外的变量值不变 // 此例说明基本数据类型按值传递. var count = 10; function addTen(count) { count += 10; return count; } var result = addTen(count); alert(count);//10;函数外的值不变 alert(result);//20;
// 此例说明对象是按值传递. function setName(obj) { obj.name = "chengdong"; obj = new Object();// 局部变量,函数执行结束就会被销毁. obj.name = "ChenZhan"; } var person = new Object(); setName(person); alert(person.name);// chengdong
// 检测类型 // typeof var n = null; alert(typeof n);// "object"; var b = true; alert(typeof b);// "boolean"; var i = 22; alert(typeof i);// "number"; var u; alert(typeof u);// "undefined"; var s = ""; alert(typeof s);// "string"; alert(typeof setName);// "function" // instanceof : 如果变量是给定引用类型的实例,则instanceof操作符返回true; var arr = new Array(); alert(arr instanceof Array);// true alert(person instanceof Object);// true