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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jan 2004
    Posts
    185
    Thanks
    2
    Thanked 1 Time in 1 Post

    if (somevar == undefined) {

    what's the syntax for "undefined" or NaN?

    trying to say
    Code:
    p == undefined ? p = 0 : p+=x;
    'if p isn't yet defined, assign a value of 0, otherwise add x's value to the whatever it is at the moment.'

  • #2
    Regular Coder
    Join Date
    Dec 2002
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by subhailc
    what's the syntax for "undefined" or NaN?

    trying to say
    Code:
    p == undefined ? p = 0 : p+=x;
    'if p isn't yet defined, assign a value of 0, otherwise add x's value to the whatever it is at the moment.'
    Try...

    Code:
    p=(typeof(p)!='undefined')?p+x:0;
    Does this help?

  • #3
    Regular Coder
    Join Date
    Jan 2004
    Posts
    185
    Thanks
    2
    Thanked 1 Time in 1 Post
    hmm i can't get it to work, probably my error rather than anything wrong with your solution, thanks for the reply.

  • #4
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Can you not use
    Code:
    p = (p == null) ? 0 : p + x;


  •  

    Posting Permissions

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