In PHP you can do if(isset($array['foo'])) { ... }
. In Javascript you often use if(array.foo) { ... }
to do the same, but this is not exactly the same statement. The condition will also evaluate to false if array.foo
does exists but is null
or false
(and probably other values as well).
What is the perfect equivalent of PHP's isset
in Javascript?
In a broader sense, a general, complete guide on Javascript's handling of variables that don't exist, variables without a value, etc. would be convenient.