Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Syntax

then(onFulfilled)
then(onFulfilled, onRejected)

Parameters

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.

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading