So in undefined's defense, depending on your goals for the language, it can be a useful differentiator between something that has no value and something that doesn't exist. Think of it like the option type if you're familiar: null = this variable/field/dict entry exists it just doesn't have a value; undefined = no such variable/field/dict entry exists.
There are of course alternatives, like the option type itself, in the case of fields and variables more commonly by throwing a no such X error, or in the case of dicts having a containsKey method. But that said, there's nothing fundamentally wrong with undefined in principle. The issue is that JavaScript combines dynamic typing and being far too liberal with implicit conversions; null == undefined should never have been decided to be true.
Even null itself, despite all the trouble it's caused, isn't necessarily implicitly bad. The problems arose from type systems that considered null the same as any other value even though the language's semantics made it a special case. C is a bit of a special case because the null address (as in 0) there really is the same as any other address; it's just one of many addresses that almost certainly don't point to data you control and will likely result in a segfault. But there's a reason later languages have been stricter about type systems and pointers.
76
u/SlenderSmurf Sep 25 '26
not a number https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSa9amnMVuKDxZ6MWURaIluhIQBOXUQCHhZpO66eEL7hg&s
38
u/nicodeemus7 Sep 25 '26
Front flap: 1
Back flap: -1
29
u/Majik_Sheff Sep 25 '26
Infinity is the uncut bulk roll at the factory. Negative infinity is a Magic The Gathering tournament.
16
u/tes_kitty Sep 25 '26
German programmers: What are you talking about? Null is the same as zero.
2
u/Ok_Actuary8 Sep 25 '26
cool, now try it in JavaScript. Better to just shit in the bushes...
2
u/Blecki Sep 26 '26
Null was bad enough.
Why did they add undefined?
1
u/anto2554 Sep 25 '26
My good friends Indeterminate and erroneous values:
1
u/Lathari Sep 25 '26
Issues with Tissues
1
u/Appropriate-Wind-184 Sep 25 '26
and the empty tube left on the holder is a memory leak. nobody ever frees it
1
u/aberroco Sep 25 '26
-1: shit on the wall.
Subnormal: an audio tape.
1
u/Electrical-Effort-20 Sep 25 '26
in 2020 we also had nil
1
u/Lawn_Meower_ Sep 26 '26
(void*)0 be like:
1
u/Random_-account Sep 27 '26
0
u/WayTooManyBirds Sep 25 '26
Inaccurate. Null would be a covered roll where you can't tell if any is left or not.
18
u/[deleted] Sep 25 '26
[removed] — view removed comment
0
u/[deleted] Sep 25 '26
[deleted] — view deleted comment