You cannot use (or test) a variable that's not been defined. I originally thought that's what you were doing with the following statement
var NEWVARIABLE = NEWVARIABLE || {};
However, thanks to Fabrício, I realized that the var declaration gets hoisted (moved to the top of the script tag and is therefore already declared when it hits the statement.
The less confusing way to test if a variable is to use typeof === 'undefined'
to see if a variable exists
var NEWVARIABLE;
if (typeof NEWVARIABLE === 'undefined') {
NEWVARIABLE = {};
}
You can use the same style when checking for properties, you don't have to use typeof
test for properties, you are allowed to test them even if they aren't defined.