What is the difference between null value and undefined value?

Post Reply
pooja soni
Posts: 2257
Joined: Tue Jul 30, 2019 2:37 pm

Wed Jul 31, 2019 11:02 am

What is the difference between null value and undefined value?
leneborma
Posts: 1
Joined: Mon Feb 10, 2020 11:36 am

Mon Feb 10, 2020 11:38 am

Null Vs. Undefined
  • The concrete difference between them is that null is explicit, while undefined is implicit.
  • In JavaScript, both null and undefined have a falsy value so when you do a equality check with == they are considered the same. If you use a strict equality check with === they are considered different.
  • Unassigned variables are initialized by JavaScript with a default value of undefined. JavaScript never sets a value to null. That must be done programmatically.
  • You can change the value of undefined by undefined=true; but you cannot change the value or null. This means that, null is object type where as undefined is undefined type.
  • While performing primitive operations, null is converted to zero (0) whereas undefined is converted to NaN.
More with examples: http://net-informations.com/js/iq/nuvsun.htm
Post Reply