Is this the arrow function?

function delay(n) {
  return new Promise(resolve => setTimeout(resolve, n))
}

the return statement in this function is a little difficult to understand.

resolve => setTimeout(resolve, n)

= > is this an arrow function?
if yes, resolve is the parameter of setTimeout,

The

delay function takes an argument n, and this setTimeout function introduces a new parameter.

it"s a little confusing. Please explain.

Mar.12,2021

https://developer.mozilla.org.
suggests viewing Promise documents


the complete state is as follows: let delay = n = > new Promise (resolve = > setTimeout (resolve,n));
promise ) is the first parameter of the callback function resolve is to change the state to success
setTimeout the first argument is the callback function's second parameter is the delay time setTimeout (resolve,n) is n millisecond later call resolve < /

function delay(time) {
  return new Promise(function(resolve){
    setTimeout(resolve, time)
  })
}

delay(3000) //3promise 

there is a setTimeout in the arrow function

Menu