0

Functions like setTimeout,setInterval etc. which are part of the browser(and not of JS engine) are asynchronous in nature, what are some other built-in functions or methods that are asynchronous, which are either part of JS engine or of a browser?

Also is it possible to implement something like setTimeout from with just javascript without using any browser APIs?

shafkathullah
  • 183
  • 6
  • 14

1 Answers1

-1

//setTimeout function without in-built function
let sleep = (interval) => {
    const previousTime = Date.now()
  while(Date.now() - previousTime < interval){
    //do nothing
  }
}

let mySetTimeout = (interval, func) => {
    sleep(interval)
  func()
}

let greet = () => {
    console.log("Hi")
}

mySetTimeout(5000, greet)