if(1){var hello ="hello";
console.log(hello);//hello}
console.log(hello);//hello//为什么会这样 使用var 变量会成为包含它的函数的局部变量functionsayhi(){var hi ="你好";
console.log(hi);}sayhi();//console.log(hi);//hi is not defined 出错//在sayhi调用完之后 会释放hi 栈内存
var a =0,
b =1,
c;
console.log([a, b, c]);//[ 0, 1, undefined ]
var的声明提升 提升到函数作用域的顶部
functiontoUp(){
console.log(var_variable);//不会报错说是is not define 而是输出值 undefinevar var_variable =1;var i =1;}/*也就是上面等价于下面的代码*//*
function toUp(){
var var_variable;
var i;
console.log(var_variable);
var_variable=1;
i=1;
}
*/toUp();