Checking JavaScript object for null subtelty
Unless you are really sure, please don't come and tell me this question
has already been asked and answered.
OK, so I believe I have found cases where I need to check for both
undefined and null for a javascript object as follows:
if (x !== undefined && x != null && x.length > 0) {...}
However, in a recent upgrade of JetBrains tools, it tells me that this is
sufficient
if (x != undefined && x.length > 0) {...}
My question is, I'm just wanting to insure that a string "x" has a length
of non-zero and is not undefined or null (with the least amount tests).
Thoughts?
No comments:
Post a Comment