There are no real advantages. And I would not say that there is a drawback if you can handle the fact that it is undefined until you install it. Understanding how types work, especially in relation to equality, occurs when you mix different types among the same operators, and cross-reference and bandwidth are more important than trying to put strict input paradigms in a dynamic language.
Now, when declaring object literals, this can save you a little hassle to declare all properties in advance.
for instance
myObject.with.way.too.much.hierarchy
If you plan to simply add these properties along the way, you will need to check for the presence of each property in this chain in any scenario where you cannot be sure that they were all defined because I am trying to access an object of a nonexistent object, even if it just checks to see if it will throw an undefined error.
So you will have something obscene:
if(myObject && myObject.with && myObject.with.way ...//ew
Note. I am personally inclined to declare all my vars ahead in function, but more like a self-documenting thing.
source share