We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
// 打印5个5 for (var i = 0; i < 5; i++) { setTimeout(() => { console.log(i) }, i * 100); } // 打印0,1,2,3,4 for (let i = 0; i < 5; i++) { setTimeout(() => { console.log(i) }, i * 100); }
console.log(a) // undefined var a = 100 console.log(b) // 报错 ReferenceError: Cannot access 'b' before initialization let b = 100
var a = 100 console.log(window.a) // 100 let b = 100 console.log(window.b) // undefined
var a var a = 100 let b let b = 100 // 报错 SyntaxError: Identifier 'b' has already been declared
let a = 100 if (true) { // 因为在该if块级作用域内,存在a的声明。所以在该作用域内,声明a之前都是访问不了a的。 console.log(a) // 报错 ReferenceError: Cannot access 'a' before initialization let a = 200 }
let a = 100 a = 200 const b = 100 b = 200 // TypeError: Assignment to constant variable. const c = { name: 'aaa', age: 18 } c.name = 'bbb' c.id = 123 c = {} // TypeError: Assignment to constant variable.
let a const b // SyntaxError: Missing initializer in const declaration
The text was updated successfully, but these errors were encountered:
No branches or pull requests
let和var的区别:
let和const的区别:
The text was updated successfully, but these errors were encountered: