setTimeout JavaScript

How does setTimeout Work with the JavaScript Engine?

If one wants a function to be executed just after a period of time T in JavaScript, what do they do? They dump it in a setTimeout and surely, just immediately after T has elapsed, the function will be run. Right? Can you predict what happens when the code below is run? You should try it out in a Node.js REPL or the console. const extractTime = (date) => date.toTimeString().split(" ")[0]; var start = new Date(); console....

January 4, 2023 · 3 min · Orim Dominic Adah
NestJS Integration Testing with TypeORM and MongoDB

Implement JavaScript's setInterval using setTimeout

I was in a job interview pair programming session where I was asked to implement JavaScript’s setInterval method without using setInterval itself. I did poorly at that interview for many reasons, including not knowing how to implement this. The question Implement the setInterval function in such a way that executing new SetInterval.prototype.start will start the function passed to it and run the function at intervals interval until the SetInterval.prototype.clear method is called....

June 23, 2021 · 4 min · Orim Dominic Adah