I understand why namespaces are good - to prevent too many global definitions and to prevent code from being overwritten, but i'm trying to dig a bit further into the following syntax:
// not safe, if there's another object with this name we will overwrite it
var MYAPPLICATION = {};
// We need to do a check before we create the namespace
if (typeof MYAPPLICATION === "undefined") {
var MYAPPLICATION = {};
}
// or a shorter version
var MAYAPPLICATION = MYAPPLICATION || {};
Ok, the first line of code isn't safe because MYAPPLICATION could be defined somewhere else or by a different library.
The second line checks to see if it exists and if it doesn't go ahead and define the var MYAPPLICATION with a new object.
My question is, what happens when MYAPPLICATION is defined beforehand? The code won't initialize the variable and the namespace isn't created? Does that mean your code would just never work? If so, what then?