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
//demo11: 区域变量覆盖全局变量
var name = 'jim'; function f(){ console.log(name); if(true){ var name = 'tom' } } f(); // undefined
//demo11.1
var name = 'jim'; function f(){ console.log(window.name); console.log(name); if(true){ var name = 'tom' } } f(); // jim undefined
//demo11.2
var name = 'jim'; function f(){ console.log(name) if(true){ var name = 'tom' } console.log(name); } f(); // undefined tom
//demo12: 循环变量泄漏为全局变量
var str = 'hello'; for(var i=0; i < str.length; i++){ console.log(str[i]); } console.log(i);
//demo21
const name = 'hello' function f(){ console.log(name); if(true){ const name = 'world' console.log(name) } } f(); output: hello world
//demo22
const str = 'hello'; for(let i=0; i < str.length; i++){ console.log(str[i]); } console.log(i); // Uncaught ReferenceError: i is not defined
The text was updated successfully, but these errors were encountered:
No branches or pull requests
1、var声明
//demo11: 区域变量覆盖全局变量
//demo11.1
//demo11.2
//demo12: 循环变量泄漏为全局变量
2、let/const
//demo21
//demo22
The text was updated successfully, but these errors were encountered: