View Full Version : In need of quick help...

11-19-2010, 10:59 PM
Ok, this might sound stupid but I swear, it's about to drive me crazy. how does one check whether or not a javascript "global" variable is undefined that will work with IE?

I've tried each variation of code and checked countless forums:

if (saved == undefined || saved == null) {
saved = new Array();

returns no error and nothing happens

if (saved == 'undefined') {
saved = new Array();

-- returns error = saved is null or not an object

if (typeof(saved) == undefined) {
saved = new Array();

returns same as above

help me please, I'm confused more then anything.
the link is also: http://doodlekins.hcents.com/designer

Basically the if statement isn't returning true and nothing on the inside of it is ever happening.

11-19-2010, 11:31 PM
alert('foo is undefined, null, 0 or false')

Philip M
11-20-2010, 09:05 AM
Or simply to detect undefined:-

var x;
alert (typeof x);
if (typeof x == "undefined") {
alert ("x is undefined");

Quizmaster: What season is said to start on the longest day in December?
Contestant: Spring.
Quizmaster: December, for God's sake!
Contestant: Summer.