Languages

JavaScript - why is null an object and what's the difference between null and undefined?

0 points
Asked by:
elmer
646

Why is null an object type and what's the difference between null and undefined?

When I'm checking:

it's the same as:

also:

1 answer
0 points
Answered by:
Admin Dirask Community
4380

1. undefined is a primitive value automatically assigned to variables that have just been declared. It is where no notion of the variable exists, it has no type and it's never been referenced before in that scope,

2. null represents the intentional absence of any object value (e.g the variable is known to exist but it is not known what the value is).

Note:

null is not the same as false or "" values, even if it's treated as falsy for boolean operations:

 

References

  1. undefined - JavaScript | MDN
  2. null - JavaScript | MDN
0 commentsAdd comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join