Out of purely intellectual curiosity why javascript takes
var z = z || [];
to initialize z (since z can be determined initially)
but without var, it throws an error (in global space)
z = z || [];
(if z was previously undefined)
In a global environment, you do not need to use VAR, although I understand that this can be bad practice.
Before you say this is a duplicate of issues such as
What is the purpose of the var keyword and when to use it (or omit it)?
Pay attention to the announcement in which "If you are in a global area, then there is no difference."
Obviously, not 100% true, given my working example.
Is this a quirk or is there legitimate logic?
Adding a summary of the answer, as I recognized it:
Thanks to Tim (see below), the key to my misunderstanding did not understand this (fundamental from javascript)
var z; does nothing if z already exists
The way this expression seems to have it in both directions, if you're wrong, suppose that "var z" is always initialized.
Starting on the left side, "var z" simply ensures that z is defined, but does not actually affect the existing value if it already exists. Then on the right, if z already exists, it is used, if not, the variable was just declared (but empty), so it will not be used, but it will not throw an error.
This is a great article about this kind of overview and upgrade in Javascript: http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting
Many thanks to the minitech and to all who contributed!