Why is null
considered an object
in JavaScript?
Is checking
if ( object == null )
Do something
the same as
if ( !object )
Do something
?
And also:
What is the difference between null
and undefined
?
Why is null
considered an object
in JavaScript?
Is checking
if ( object == null )
Do something
the same as
if ( !object )
Do something
?
And also:
What is the difference between null
and undefined
?
null
is an object. Its type is null.undefined
is not an object; its type is undefined.The other fun thing about null, compared to undefined, is that it can be incremented.
This is useful for setting default numerical values for counters. How many times have you set a variable to -1 in its declaration?