Outline
const
and let
were added in ES6 to solve an issue with var
known as variable hoisting.
var
can be reassigned to any value, but uses lexical scope. If you declare a var
inside of a block, it will still exist outside of that block.
let
is just like var
except that it's scope is limited to the block where it was declared.
const
is block-scoped just like let
, but has restrictions. A const
cannot be redifened or declared, but can be modified if it contains a complex data type.