ES6 in Depth
  • Introduction
  • Installation
  • Block Scope
    • Constant
    • Use cases
  • Template String
    • New String Methods
    • Tagged Template Literal
  • New Number Methods
  • Arrow Function
    • Default Parameters
    • Lexical This Scope
    • Where not to use arrow function
  • Object Enhancement
  • New Array Methods
    • For Of
  • Spread Operator
  • Destructuring
    • Array Destructuring
  • Class
  • Symbols
  • New Data Structures
    • Set
    • Map
    • WeakSet
    • WeakMap
    • Iterators
    • Generators
  • Promise
  • Import Export
Powered by GitBook
On this page
  • Use case 1
  • Use Case 2

Was this helpful?

  1. Block Scope

Use cases

Use case 1

// Before
(function(){
    let x = 10; // x not available outside
})();

// Now
{
    let x = 10; // x not available outside 
}

Use Case 2

for(let i=0; i<10; i++){
    setTimeout(function(){
        console.log("number " + i);
    }, 1000);
}
PreviousConstantNextTemplate String

Last updated 4 years ago

Was this helpful?