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 2 of 2

Thread: var test =a||b;

  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Posts
    179
    Thanks
    17
    Thanked 0 Times in 0 Posts

    var test =a||b;

    I often saw a variable assignment like this:

    var onComplete = onComplete || false;


    My understanding: if onComplete is valid, return the value of ocComplete; otherwise, return false.

    --Is this correct understanding?

    --If so, how to determine if the onComplete is valid or not? Use onComplete ==null or else?


    Thanks


    Scott

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by otnj2ee View Post
    --If so, how to determine if the onComplete is valid or not? Use onComplete ==null or else?
    || operator:

    http://www.javascriptkit.com/jsref/c...perators.shtml

    If the first expression does NOT evaluate to true (ie: it's null or undefined), then the value of the second expression is evaluated and returned.
    best regards


  •  

    Posting Permissions

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