C
Chris Beall
If you want your code to be bulletproof, do you have to explicitly check
for the existence of any possibly-undefined variable?
Example: window.outerHeight is defined by some browsers, but not others.
It would therefore seem prudent, before using this variable, to do
something like:
if (typeof (window.outerHeight) != "undefined") { do stuff that
refers to this variable }
else { work around the fact that the variable isn't defined }
1. Is this really necessary? Bad things seem to happen if even
relatively harmless use is made of an undefined variable, such as
document.write ("Height is " + window.outerHeight)
By 'bad things" I mean that the whole script comes to a halt.
2. Aside from something like:
(typeof (window.outerHeight) != "undefined") ? x = window.outerHeight
: x = "undefined"
is there a more concise way of doing this?
3. Are the consequences of using an undefined variable actually
documented in any authoritative place?
Chris Beall
for the existence of any possibly-undefined variable?
Example: window.outerHeight is defined by some browsers, but not others.
It would therefore seem prudent, before using this variable, to do
something like:
if (typeof (window.outerHeight) != "undefined") { do stuff that
refers to this variable }
else { work around the fact that the variable isn't defined }
1. Is this really necessary? Bad things seem to happen if even
relatively harmless use is made of an undefined variable, such as
document.write ("Height is " + window.outerHeight)
By 'bad things" I mean that the whole script comes to a halt.
2. Aside from something like:
(typeof (window.outerHeight) != "undefined") ? x = window.outerHeight
: x = "undefined"
is there a more concise way of doing this?
3. Are the consequences of using an undefined variable actually
documented in any authoritative place?
Chris Beall