Update let (#24190)

* Update index.md

* Formatting changes
pull/25216/head^2
Stefan 2018-12-19 07:20:01 +00:00 committed by Manish Giri
parent 1db49a8087
commit 375e702b57
1 changed files with 13 additions and 0 deletions

View File

@ -29,6 +29,19 @@ console.log(c); // 10
console.log(a); // 50 console.log(a); // 50
``` ```
### Differences with `var`
Hoisting - `let` variables are not initialized until their definition is evaluated:
```js
function action() {
console.log(a); // undefined
console.log(b); // ReferenceError
var a = 1;
let b = 2;
}
```
## Const ## Const
Const is used to assign a constant value to the variable, and the value cannot be changed. It is fixed. Const is used to assign a constant value to the variable, and the value cannot be changed. It is fixed.