Does SetInterval make work in a separate thread? How does this method work?

I looked around trying to figure out how SetInterval , but only found how to use it. I already know its functionality, I'm just wondering how it can run something in a separate thread when JS does not support threads (at least what I'm reading).

I hope I correctly formulated the question.

Thanks.

+5
source share
1 answer

setInterval does not start anything in another thread. He plans to start something at certain points in time if the JS runtime at this time does not work.

You can try this behavior like this:

 setInterval(function(){ alert("Hello"); }, 1000); while (true) { } 

An infinite loop will prevent the function from starting because JS runtime is stuck in the loop.

+3
source

All Articles