简体   繁体   中英

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM