Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation In need of quick help...

    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:
    Code:
    if (saved == undefined || saved == null) {
    	alert('saved');
    	saved = new Array();
    }
    returns no error and nothing happens
    Code:
    if (saved == 'undefined') {
    	alert('saved');
    	saved = new Array();
    }
    -- returns error = saved is null or not an object
    Code:
    if (typeof(saved) == undefined) {
    	alert('saved');
    	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.
    Last edited by trickell; 11-19-2010 at 10:02 PM.

  • #2
    Regular Coder
    Join Date
    Apr 2010
    Posts
    163
    Thanks
    3
    Thanked 25 Times in 25 Posts
    Code:
    if(!foo){
         alert('foo is undefined, null, 0 or false')
    }

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Or simply to detect undefined:-

    Code:
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •