Node.js ECMAScript 2015 (ES6) with Node.js const/let declarations


Example

Unlike var, const/let are bound to lexical scope rather than function scope.

{
  var x = 1 // will escape the scope
  let y = 2 // bound to lexical scope
  const z = 3 // bound to lexical scope, constant
}

console.log(x) // 1
console.log(y) // ReferenceError: y is not defined
console.log(z) // ReferenceError: z is not defined

Run in RunKit