why does void inside of promise.then not return undefined?


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 :


then(onFulfilled, onRejected)


onFulfilled (Optional)
A Function asynchronously called if the Promise is 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.


void produces such a "not a function", specifically undefined, so the onFulfilled function is implicitly replaced with x => x.

Leave a Reply Cancel reply