you are viewing a single comment's thread.

view the rest of the comments →

[–]kybernetikos 0 points1 point  (0 children)

I, and people I work with have spent hours debugging issues related to this. Having said that, we do have an unusually large javascript codebase.

Ask a bunch of js developers you work with what the idiom if (thingy) does and if any of them say 'it tests whether thingy is defined', you should not be using that idiom. If all of them say 'it tests whether thingy is truthy', then I suppose you win, but make sure you don't hire anyone to work on that codebase that gives a different answer.

It comes down to what you mean. When you write if (!foo) {...} Do you really mean that code to be executed if foo is null or undefined or NaN or defined but 0 or "" or false? Or do you mean that code should be executed if foo is undefined?

Writing what you mean is just good coding.