logoalt Hacker News

jfengeltoday at 12:14 AM1 replyview on HN

I occasionally run into problems with JS weird parsing rules. My favorite is:

    return
        x 
Which does not return. It returns undefined.

Typescript helps a lot with that. A linter will probably flag it as well. Still, JS went way out of its way to accept just about anything, whether it makes sense or not.


Replies

galaxyLogictoday at 6:19 AM

That is what I lament too. So I've started to use the comma-operator to make sure my return statements don't care about line-breaks. I often write:

return 0,

x;

I find this a mildly amusing discovery for myself because it took me a long time to figure out a useful use for the comma-operator.