Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

This is a matter of taste, of course, as we don't have a good study of programming code comprehension yet, but I think the coolest part of JS are cond statements using the trinary operator:

    var foo = predicate  ? "one" :
              predicate2 ? "two" :
                           "default";
And short-circuit and/or:

    var foo = uncheckedFoo || "default";
    var wiz = (bar && bar(foo)) || "default";
Truthy values get in the way sometimes (especially 0), but it sure as hell beats a ton of if...else crud.

Worst part of JS, while we're at it:

    true == "0" == 0 == false


Here's another neat example of short-circuit or:

    function getFoo(f) {
        if (f) {
            if (foos[f]) {
                return foos[f];
            } else {
                return f;
            }
        } else {
            return "error";
        }
    }
Is (almost) the same as...

    function getFoo(f) {
        return foos[f] || f || "error";
    }
The difference in behavior being if foos[undefined] is set...


     true == "0" == 0 == false 
This is untrue.

    > true == "0"
    false
    > "0" == 0
    true
    > 0 == false
    true
    > true == "0" == 0 == false
    false


I think he meant something like this:

    true == !0 == "0" == false
Which still isn't that interesting, since it is much the same as:

    true == (false == false)
More interesting, something like:

    > ! 0 ==   "0"
    false
    >   0 == ! "0"
    true
Since "!" acts as if false === 0.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: