getify / You-Dont-Know-JS

A book series on JavaScript. @YDKJS on twitter.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

null vs. undefined

Violet-Bora-Lee opened this issue · comments

Yes, I promise I've read the Contributions Guidelines (please feel free to remove this line).


Please type "I already searched for this issue":

I already searched for this issue

Edition: (1st or 2nd)
2nd

Book Title:
Book1, Get Started

Chapter:
Chapter 2: Surveying JS

Section Title:
Values

Question:
According to the resources I've read, it's not recommended to use undefined rather than null.

It contradicts the contents of the section.

Many developers prefer to treat them both consistently in this fashion, which is to say that the values are assumed to be indistinguishable. If care is taken, this is often possible. However, it's safest and best to use only undefined as the single empty value, even though null seems attractive in that it's shorter to type!

Could you more elaborate?

FYI. I'm translating the books into Korean with the agency.

Different authors have different opinions.

I got it! I just wanted double check. Thanks for your rapid response 👍