I have learned Javascript for several months, but I still could not differentiate null and undefined. This may sound silly, I know. So, in this article, I decided to dive deep the differences between the two.

Before we start, we have to understand the 7 primitive data types:

  • string
  • number
  • bigint
  • boolean
  • undefined
  • null
  • symbol

And there are 6 common known falsy values in Javascript(full list), which are:

  • keyword false
  • number 0 and -0 (Also 0n and -0n )
  • Empty string values: “”'' , ````
  • null (the absence of any value)
  • undefined
  • NaN — not a number

As we can see, null and undefined are treated as falsy for boolean operations. There is something I would like to discuss that are added into ES2021 (or ES12) that is related to null and undefined , which we would explore at the end of this article.

#primitive-values #javascript

Null and Undefined in Javascript
1.20 GEEK