Falsey values in JavaScript

Viewed 29945

I had an interesting interview question today that stumped me a little. I was asked about falsey values. So undefined, NaN, null, 0, and an empty string all evaluate to false. What is the reason this is useful to know in JavaScript? The only thing I can think of is instead of having to do this:

if (mystring === '' || mystring === undefined) { }

I can do this:

if (!mystring)

Is this the only useful application?

6 Answers
Related