3 ms·
There are: 1. falsy values 0, -0, 0n, '', null, undefined, NaN 2. null 3. undefined 4. absence of property and property set to undefined You have to know diffe
by mirekrusin 6y ago
There are:
1. falsy values 0, -0, 0n, '', null, undefined, NaN
2. null
3. undefined
4. absence of property and property set to undefined
You have to know differences between those when coding in js/ts/flow. Ie. no 4. has implications when iterating ie. Object.keys({ foo: undefined }).length === 1.
Education around those - yes, but blacklisting null? Sounds a bit silly, however I agree that most developers overuse null when they actually mean undefined.
One example in code where null vs undefined can be used is sql.update(table, where, { foo: null, bar: 1 }) - meaning update foo to null vs sql.update(table, where, { foo: undefined, bar: 1 }) - where undefined means, don't do anything with that column. This helps a lot because it's much more verbose to conditionally construct object with a property or without it, however it's easy to set it defined/undefined.
- deleted 6y ago[deleted]