3 ms·
`then` is meant to return a promise, i.e. return an asynchronous value; it should never synchronously throw an error. That said, I somewhat agree (although in
by domenicd 13y ago
`then` is meant to return a promise, i.e. return an asynchronous value; it should never synchronously throw an error.
That said, I somewhat agree (although in JavaScript it should be `undefined`, not `null`). If we were starting clean, instead of with tons of code in the wild that did `.then(null, onRejected)` or `.then(false, onRejected)`, we would have the resulting promise be rejected with a `TypeError` if `onFulfilled` was neither `undefined` nor a function.
- willvarfar 13y agoHmm null is easier to pass on purpose and undefined is easier to pass by accident. Sending in undefined for a non-trailing argument takes effort. I think the literal null is far more communicative of the developers intent. But the general point is, JS APIs tend to fail silently on error by design and that's something that bugs me, literally. Bugs. Lots of them. I agree regards returning a failure rather than throwing an exception, though.