October 2018
Intermediate to advanced
590 pages
15h 5m
English
As mentioned earlier, in ES6, you can use let to define variables or use const to define constants, and they will have block-level scope. And in the same scope, you can not redefine a variable using let. Also, you cannot access a variable or a constant that is defined with let or const before its declaration, since there is no variable hoisting with let or const.
Let's see the following workout example:
1. function workout() {2. let gym = 'Gym A';3. 4. const gymStatuses = {'Gym A': 'open', 'Gym B': 'closed'};5. for (let gym in gymStatuses) {6. console.log(gym + ' is ' + gymStatuses[gym]);7. }8.9. {10. const gym = 'Gym B';11. console.log('Workout in ' + gym);12. // The following will throw TypeError13. // ...
Read now
Unlock full access