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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Location
    NYC
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    I dont recognize this character in code

    Hi, it's my first post and first thread, actually I joined to ask this question.
    I did try searching first but for some reason when I put this character in google search fields
    I never find what I want, maybe not being recognized.

    here's the code
    Code:
    this.size=a.size||2000;
    this.handle_event=a.handle_event||'click';
    my question ... what is the || character(s)?

    I'm sure this must be laughably simple and thanks in advance
    (new to learning js)
    Last edited by PrimeLens; 12-31-2010 at 04:24 AM.

  • #2
    Regular Coder Nile's Avatar
    Join Date
    Jun 2008
    Posts
    280
    Thanks
    2
    Thanked 46 Times in 46 Posts
    Logical OR. Some rules to remember:
    If the first expression evaluates to true, the value of that expression (unchanged) is returned.
    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.
    false || anything always evaluates to false
    true || anything always evaluates to true
    http://www.javascriptkit.com/jsref/c...perators.shtml

  • Users who have thanked Nile for this post:

    PrimeLens (12-31-2010)

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Location
    NYC
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Funnily enough I knew || meant OR from actionscript days but seeing it in the assignment of a variable threw me! Double pipe what?
    Thanks Nile.

  • #4
    Regular Coder Nile's Avatar
    Join Date
    Jun 2008
    Posts
    280
    Thanks
    2
    Thanked 46 Times in 46 Posts
    No problem

  • #5
    Regular Coder Krupski's Avatar
    Join Date
    Dec 2010
    Location
    United States of America
    Posts
    505
    Thanks
    39
    Thanked 47 Times in 46 Posts
    Quote Originally Posted by PrimeLens View Post
    Funnily enough I knew || meant OR from actionscript days but seeing it in the assignment of a variable threw me! Double pipe what?
    Thanks Nile.
    Single and double mean different things.

    A single "and" or a single "or" are bitwise operators. For example, "1 | 2" is "3" because 0001 or 0010 is 0011.

    Another example: "2 & 6" is "2" because 0010 and 1010 is 0010.

    Double "and" and "or" are comparison opeartors. For example (pseudo code):

    Code:
        if (enough_money && want_car)
        {
            purchase_car;
            pay_for_car;
        }
    ...wheras....

    Code:
        if (not_enough_money || want_car)
        {
            purchase_car;
            cannot_pay_for_car;
            kicked_out_of_dealership;
        }

    Make sense?
    "Anything that is complex is not useful and anything that is useful is simple. This has been my whole life's motto." -- Mikhail T. Kalashnikov


  •  

    Posting Permissions

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