Using undefined is technically correct, but has little to no point, you'd be better off declaring the variable with a NULL consider this code:
var obj = {
oUn : undefined,
oNull : null
};
document.body.appendChild(document.createTextNode(
typeof obj.oUn
+ ' ' + typeof obj.oNull
+ ' ' + typeof obj.doesNotExist
));
Although yes, in FireBug, and maybe other debuggers (did not check) obj.oUn does come up, but if you try to check it within JS you get the same result as if its not even defined. (Note that the "typeof obj.doesNotExist" returned the same value as "typeof obj.oUn" although, it was not defined). Though that said if you check it within a for loop you do get it i.e. this will display the obj.Un
var obj = {
oUn : undefined,
oNull : null
};
document.body.appendChild(document.createTextNode(
typeof obj.oUn
+ ' ' + typeof obj.oNull
+ ' ' + typeof obj.doesNotExist
));
document.body.appendChild(document.createElement('br'));
var name;
for(name in obj) {
document.body.appendChild(document.createTextNode(name));
document.body.appendChild(document.createElement('br'));
}
So I guess it depends on why you need it. By in large I would say if you do not need the name per say (i.e. your code already knows the name) then do not even declare it and simply use
var globalVar = {};
You can always extend on it latter once you need it or if you need it, then use NULL, because you can actually check in JS if its in use by checking if the value is NULL or not. With undefined you'd have no way of knowing, because it does not differ at all from a value that is not in use and you'd need to make a cumbersome helper function in order to find out.
globalVar.myVar3 = null;