2

I was working on a project with JavaScript and I was wondering if I used setInterval() and set it to run each millisecond, would that cause performance issues? Would calling the function whenever needed be better performance wise? Or setInterval() doesn't affect the performance?

Skelelele
  • 21
  • 4

1 Answers1

1

if you do setInterval , your function will be added to the stack each x ms. That doesn't mean that it will be executed each x ms. Indeed the stack may not be empty at the moment the function is added to it. So you will run your function with a period which is at least x ms (no precision guaranteed!). That's the only performance issue I know about setInterval Hope that helped!

Fanyo SILIADIN
  • 802
  • 5
  • 11