function which wait 3 secounds and call itself in javascript

index.tsx
function delayedFunction() {
  setTimeout(() => {
    delayedFunction();
  }, 3000);
}
87 chars
6 lines

The function delayedFunction uses setTimeout to wait for 3 seconds before calling itself recursively.

Note: This implementation will not be accurate to exactly 3 seconds as it has a delay inherent to the event loop. If precise timing is required, setInterval may be a better option.

gistlibby LogSnag