var:全局聲明,會(huì)改變?nèi)肿兞康闹蛋旰埃M(jìn)而污染全局變量
var a=2;
{
var a=3;
}
console.log(a);//3
let:局部聲明坡慌,不會(huì)改變?nèi)肿兞康闹?/h2>
var a=2;
{
let a=3;
}
console.log(a);//2
const:常量,聲明了就不能改變
const a = 1;
var a = 2;
console.log(a);//編譯報(bào)錯(cuò)
var a=2;
{
let a=3;
}
console.log(a);//2
const a = 1;
var a = 2;
console.log(a);//編譯報(bào)錯(cuò)