2 ms·
I actually like having both "nil" and "undefined" in Javascript! "Absence of value" is different from "data that happens to be some kind of empty data point".
by nerdponx 5y ago
I actually like having both "nil" and "undefined" in Javascript!
"Absence of value" is different from "data that happens to be some kind of empty data point".
Also part of the issue is function arguments, there's no arity-checking by default.
- wruza 5y agoRight, and it allows for arguments of functions and destructurizers to be undefined for default and null for null. Absent and empty are really different concepts. These being merged, separate, implicit or explicit, all may be hard to manage, but at least in the case of (undefined & null) it is a most uncrippled value system. JSON also got it right, allowing null but not undefined. At the end of the day all that matters is a programmer’s convenience. Corner cases exist everywhere. With all flaws of js, this is where it shines: var t = undefined var u = {b:1} var {a=42, b=true} = {undefined, …t, …u} // a==42, b==1 Another related issue with Lua is: table.insert(t, string.gsub(s, “1”, “2”)) -- happy debugging It is full of these little design decisions that put your feet to danger not any less than others.
- int_19h 5y agoIt would be nice if "undefined" consistently meant absence, but it's not quite that: console.log('foo' in {foo: undefined}); // true!