I was reading some code using the Promise object.
There is a setTimeout
function with three parameters, I am wondering what does the third parameter do? Because usually it only has two parameters.
The code is like below:
function timeout(ms) {
return new Promise((resolve, reject) => {
setTimeout(resolve, ms , 'done');
});
}
timeout(1000).then(value => {
console.log(value);
});
I noticed that the third parameter is passed to the resolve
function, but why can I use it in the function in then
? How does it work?