Instead of using
var to declare local variables, we use
let. The main difference is that
var is scoped to a function, while
let are scoped to a block.
Additionally, variables declared with
const can only be assigned a value once. Assigning another value to the same name will throw a compiler error. Note that if the value assigned to a
const variable is an object or array, the object or array may still be modified. In other words, it's only the variable name that is bound permanently -- the value itself is still mutable.
You'll notice that the compiled output replaces
var. You'll also notice that Babel transforms
const a = 3 into