Sobes.tech
Junior

Mida tuleb teha, et funktsioon setTimeout täidetakse hiljem?

sobes.tech AI

Vastus AI-lt

To have the function passed to setTimeout execute later, you need to increase the delay value (in milliseconds) passed as the second argument. For example, if it is currently setTimeout(fn, 1000), to execute it later, you can specify a larger number, such as setTimeout(fn, 5000) — then the function will execute after 5 seconds.

setTimeout(() => {
  console.log('Will execute after 5 seconds');
}, 5000);

It is also important to understand that the minimum delay in browsers is usually not less than 4 ms, and that setTimeout does not guarantee exact execution time, only the minimum delay. If you want to delay the execution even further, simply increase the delay time.