let y const

  • 2 nuevos tipos de "variables": let y const
  • Ambas con block scope

block scope

antes (ES5)

var arr = [1, 2, 3];
for (var i = 0; i < arr.length; i++) {
  // i from 0 to 2
}
i; // 3
{
  var TEMPERATURE = 32;
  TEMPERATURE = 16;
  TEMPERATURE // 16
}
TEMPERATURE; // 16

después (ES2015)

var arr = [1, 2, 3];
for (let i = 0; i < arr.length; i++) {
  // i from 0 to 2
}
i; // ReferenceError: i is not defined!
{
  const TEMPERATURE = 32;
  TEMPERATURE = 16;
  TEMPERATURE; // 32
}
TEMPERATURE; // ReferenceError: TEMPERATURE is not defined!

Más info:

⛏   ES6 Katas: Block Scope

Hacer las siguientes katas:

results matching ""

    No results matching ""