mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-28 21:32:20 +00:00
修改let
This commit is contained in:
parent
dc6437d0b2
commit
83778d608b
@ -145,7 +145,9 @@ function f() { console.log('I am outside!'); }
|
||||
|
||||
```
|
||||
|
||||
上面代码在ES5中运行,会得到“I am inside!”,但是在ES6中运行,会得到“I am outside!”。
|
||||
上面代码在ES5中运行,会得到“I am inside!”,但是在ES6中运行,会得到“I am outside!”。这是因为ES5存在函数提升,不管会不会进入if代码块,函数声明都会提升到当前作用域的顶部,得到执行;而ES6支持块级作用域,不管会不会进入if代码块,其内部声明的函数皆不会影响到作用域的外部。
|
||||
|
||||
需要注意的是,如果在严格模式下,函数只能在顶层作用域和函数内声明,其他情况(比如if代码块、循环代码块)的声明都会报错。
|
||||
|
||||
## const命令
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user