Reputation: 16373
If I have a declaration as follows:
var j;
does j==null
until I set it equal to something?
Upvotes: 26
Views: 32768
Reputation: 11352
No, it has the default value of undefined
But if want to use the !j
condition, it will work with both the values (i.e. undefined or null)
Note that (j==null)
is true
, but (j===null)
is false
... JavaScript have "falsy" values and sometimes unexpected rules to convert values, plus fancy ===
operator to compare value and type at the same time.
Upvotes: 43