4 ms·
Null coalescing is already possible with ||. Though I'd like ?? If it worked for undefined coalescing as well.
by Forge36 8y ago
Null coalescing is already possible with ||.
Though I'd like ?? If it worked for undefined coalescing as well.
- untog 8y agoYou still have to be more verbose, though. You can't do obj1?.obj2 with ||, not could you do obj1?.method()
- coldtea 8y agoHow does || differentiate null from e.g. 0 or ""?
- GordonS 8y agoIt doesn't - it tests for a "truthy" value.
- charrondev 8y agoThese are not the same. let val = 0 val || 30 // 30 val ?? 30 // 0 The same goes for other falsy values.