Hacker Newsnew | comments | show | ask | jobs | submit login

I actually did a === check for just that reason, since if you define _ = {}, then passing in a real object that is {} will also return true for _ == {}



Nope:

    js> a = {}
    [object Object]
    js> b = {}
    [object Object]
    js> a == b
    false
== only casts between certain primitive types, it doesn't do a deep comparison:

    js> x = null
    null
    js> y = undefined
    js> x == y
    true
    js> x === y
    false
Also undefined comparisons are still true with ===:

    js> var _
    js> _ === undefined
    true

But you're right, === should be the default choice, and only use == if you have a good reason.

-----




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: