vars are scoped to
functions, and they can "see" outside their functions to the outer context.
varstill works that way, using functions as containers, but there are two new ways to declare variables:
}blocks as containers, hence "block scope". Block scoping is most useful during loops. Consider the following:
varin the sense that its data is read/write.
letis also useful when used in a for loop. For example, without let, the following example would output
var, the value would be scoped in a way that people would expect.
constis read-only. Once
consthas been assigned, the identifier cannot be reassigned.
constreference, below we've switch to using let for the literal object.