Hacker News new | past | comments | ask | show | jobs | submit login

I'm a little confused; what's going on in the part of the main if condition after the &&? It looks like the author intended to check if any of e.which, e.charCode, or e.keyCode equal 9, but obviously that's not what would happen.



'obviously'?

The code looks fine to me, c.f.:

    $ node
    > undefined || undefined || 4
    4
    > undefined || 9 || 4
    9
The || operator evaluates to the first of its two operands if it is truthy, or its second operand otherwise

    > undefined || false
    false
    > false || undefined
    undefined
So:

    > e = {keyCode:9}
    > e.which || e.charCode || e.keyCode
    9




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: