3 ms·
Invalid JSON parsing as `null` would be an exciting API decision, haha. One thing I think I like about JS over Python is that empty containers are "truthy". Th
by repsilat 8y ago
Invalid JSON parsing as `null` would be an exciting API decision, haha.
One thing I think I like about JS over Python is that empty containers are "truthy". This, combined with non-raising missed lookups, tends to be pretty ergonomic. For me, at least.
Though it is messier -- in Python `key in d` is well entrenched as an idiom, and in JS `if(d.key)` misfires if the value is zero, and `if(d.key === undefined)` doesn't discriminate between a missed lookup and a stored `undefined`. Though the latter must be discouraged, right?
- masklinn 8y ago> Invalid JSON parsing as `null` would be an exciting API decision, haha. PHP's json_decode does that. And yes `null` is also returned as a PHP NULL. > Though it is messier -- in Python `key in d` is well entrenched as an idiom, and in JS `if(d.key)` misfires if the value is zero Or false, or null, or the empty string, or NaN. FWIW `if (key in d)` also works in JS if d is a native object, though you need `d.has(key)` if d is an actual Map object instead.