I don’t understand why Mozilla calls this an Array ‘Literal’ when it’s defined using the VARIABLE keyword and it can be completely changed…
var coffees = ["French Roast", "Colombian", "Kona"];
Can anyone explain this to me?
https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Core_Language_Features#Object_literals
The written, literal value
["French Roast", "Colombian", "Kona"]actually can’t be changed — it’s an array with those exact three strings, and nothing else. Once the literal is stored in a variable, the value of the variable can change, so the variable is non-literal.You can even change the value of the structure represented by the literal on the fly, e.g.,
[1,2,3].push(4), but even so, the written value of[1,2,3]is a literal that refers to an array with those three elements.It’s much like using numeric literals, e.g.,in
a = 1 + 2the expressions1and2are unchangeable literals, but they can be combined to produce new results (and obviously the value ofacan change).