r/webdev • u/craigtaub • Jun 17 '18
My most hated JavaScript features
https://medium.com/@tabu_craig/my-worst-javascript-features-465378d5ad43
0
Upvotes
1
u/govision Jun 17 '18
It's non-reusable code and when big enough it's not really readable. Hence ... typescript
2
u/birjolaxew Jun 17 '18
I think your problem with
nullmostly stems from you misunderstanding whatnullmeans in JS. You seenullas being equal toundefined. It isn't.undefinedshould be seen as an indication that the value is unset, whilenullshould be seen as an indication that the value was explicitly set to be nothing (as described by MDN: "The value null represents the intentional absence of any object value").It is important to maintain this explicit non-value when getting e.g. default values - if you have e.g. a field in your storage indicating the gender of a user, and you give the user the option of choosing "would rather not disclose", then you would use
nullto represent this non-value. Defaulting to one of the genders would go against the point of usingnull. When you initialize the field without knowing what the user's gender is, you set it toundefined.