null vs. undefined
Violet-Bora-Lee opened this issue · comments
Bora Lee commented
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
.
- https://2ality.com/2021/01/undefined-null-revisited.html#my-approach
- https://www.amazon.com/Professional-JavaScript-Developers-Nicholas-Zakas/dp/1118026691
- https://javascript.info/types#the-undefined-value
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.
Kyle Simpson commented
Different authors have different opinions.
Bora Lee commented
I got it! I just wanted double check. Thanks for your rapid response 👍