My co-worker wrote structurally this kind of code:
Promise.resolve(2).then(void console.log('3')).then(x => x + 2)
Can someone explain why the x argument is not "undefined" in the last then
>Solution :
Syntax
then(onFulfilled) then(onFulfilled, onRejected)Parameters
onFulfilled(Optional)
A Function asynchronously called if thePromiseis fulfilled. This function has one parameter, the fulfillment value. If it is not a function, it is internally replaced with an identity function ((x) => x) which simply passes the fulfillment value forward.http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then
void produces such a "not a function", specifically undefined, so the onFulfilled function is implicitly replaced with x => x.