Skip to content
New issue

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

【ES6/let与const】 #4

Open
Kelichao opened this issue Jan 18, 2017 · 0 comments
Open

【ES6/let与const】 #4

Kelichao opened this issue Jan 18, 2017 · 0 comments

Comments

@Kelichao
Copy link
Owner

Kelichao commented Jan 18, 2017

let

  • 声明变量,放置于代码块中,只要是通过括号(小括号,大括号)包裹起来的,外部都无法访问到
// 用法一
for (let a = 1;a <=2; a++) {
	// 用法二
	let c = 123;
}
console.log(a);
console.log(c);

let所解决的经典闭包问题

效果类似于在每轮循环内部嵌套了一层匿名函数

var a = [];
for (let i = 0; i< 10; i++) {
	a[i] = function() {
		console.log(i);
	};
}

a[6]();// 输出为6,而不是10;

可以用任意多个块级作用域嵌套

{{{{{{let a=123}}}}}}

const

  • 定义常量,定以后不可以进行改变

注意点

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant