Hacker News new | ask | show | jobs
by toolslive 1860 days ago
besides being really insane typing wise, javascript also both really lenient and unpredictable in what it accepts as expressions. Try to guess the result of the following expressions:

    > [] + []
    >
    > {} + []
    >
    > [] + {}
    >
    > {} + {}
It means that if you feed it nonsense it does not stop you but happily carries on and explodes a few milliseconds later somewhere else. Another can of worms is the difference between null, 0,undefined, '', ....

Ok, you got me worked up. I need to go for a run to blow off steam.

2 comments

That is just javascript trivia that one rarely encounters in real code, and shouldn't be used to dismiss the entire language.
To borrow a Stroustrup quote

> "There are only two kinds of languages: the ones people complain about and the ones nobody uses".

I'm not a fan of JavaScript but I do like TypeScript.

If your statement begins with a curly brace, that brace is a code block, NOT an object literal.

Coercion rules are terrible, but they were only added to the language due to developer demands.

If you worry about zero or empty string, you’ll have problems in tons of other languages. Null vs undefined is less understandable along with the old ability to redefine undefined as it was a variable . In any case, I agree that one of the two shouldn’t exist.