3 ms·
> and therefore the value is null That depends on the interpreter: A good implementation of json distinguishes between defined and undefined keys in the object
by mattashii 4y ago
> and therefore the value is null
That depends on the interpreter: A good implementation of json distinguishes between defined and undefined keys in the object. Think hasattr(obj, "key") in python, or undefined != obj["key"] in js.
- Waterluvian 4y agoGosh. If “undefined” was part of JSON and it was always 100% semantically identical to “this key doesn’t exist on this object” then I could see myself not hating “undefined”. Unfortunately “undefined” in javascript isn’t even the same as “key doesn’t exist.” It’s just another null type.
- jffry 4y agoUntil you try JSON.stringify({a: null, b: undefined})
- mananaysiempre 4y agoWhich in turn led V8 to invent TheHole[1], a true unset value, as an implementation detail (unavailable to the user). Honestly, it seems to me that pre-strict-mode JavaScript actually made a fair attempt at making "undefined" a genuine missing value, except that then implied semantics people disliked, like an undefined variable reference having the value of "undefined" instead of being an error. Lua seems mostly OK having an actual nil, though. (There is admittedly some gnarliness, like a vararg function f being able to distinguish f(1,2,nil) from f(1,2).) [1] https://stackoverflow.com/q/61420580 https://stackoverflow.com/q/61420580