var has. I heard Rick Waldron of TC39 say that function scope is basically a bug, so the introduction of
let is basically a bug fix. 🙂
const statement is similar to
let, but also creates an “immutable binding.” That means the variable can’t be reassigned, and increment and decrement operators can’t be applied to the variable.
const x = 3; x = 5; throws a
TypeError exception, and so does
const x = 3; x++;.
Const is not an immutable variable though, contrary to its semantics.
const x = ; x.push(4); is error-free code, and results in
x = [3,4].
I like and use the
let statement. I don’t use
const because the effort to keep its utility in my head outweighs its functional benefits while I’m writing code.