变量的使用域不一样,你用下面的语句就知道了。<html>
<head>
</head>
<body>
<script> function p(n)
{
n+=10;
return n;
}
var n = new Number(100);
alert(p(n));
alert(n);
// 为甚显示不是110呢???
</script>
</body>
</html>
<head>
</head>
<body>
<script> function p(n)
{
n+=10;
return n;
}
var n = new Number(100);
alert(p(n));
alert(n);
// 为甚显示不是110呢???
</script>
</body>
</html>
<head>
</head>
<body>
<script>
function p(o)
{
alert("type1=" + typeof o);// 此处是一个object
o+=10;
alert("type2=" + typeof o);//此处已经成了一个基本类型,所以原来的object的值还是原来的,这中间类型发生了转换
} var n = new Number(100);
alert("n is " + typeof n);
p(n);
alert(n);
// 为甚显示不是110呢???
</script>
</body>
</html>
中n是局部变量
var n = new Number(100);
中n是全局变量;
作用域不一样
{
n = n+10; //这里实际上调用了Number对象的Valueof方法阿,已经转换成值类型了 ,表达式右边的n是Object对象引用,左边副值之后就是值了
}