変数値の種類:数値タイプと参照タイプ

1121 ワード

javascript高級プログラム設計70

//  :    、    ,            69 
var color = "red";
function changeColor(color){   //  color    changeColor       。             
    console.log(arguments)   //[callee:function,Symbol()]
    if(color === "red"){
        color = "blue";
    }else{
        color = "blue";
    }
}
changeColor(color);   
console.log(color)   //red

var color = "red";
function changeColor(){
    console.log(arguments)  //[callee:function,Symbol()]
    if(color === "red"){
        color = "blue";
    }else{
        color = "blue";
    }
}
changeColor();   
console.log(color)   //blue
//グローバル変数と局所変数var a=10;sayHi();function sayHi(){
var a = a + 10;
alert(a);
return a;   //return a        a,     alert(a) //10
}alert(a)alert(sayHi()+10)実行結果:NaN 10 NaN NaN
var a=10sayHi();function sayHi(){
var a = "a" + 10;
alert(a);
alert(typeof a);
return a;   //return a        a,     alert(a) //10
}alert(a)alert(sayHi()+10)実行結果:a 10 string 10 a 10 string a 1010