Recursive setTimeot and/or setInterval. What's the difference?

Hello. Today we learned about recursive setTimeout and did not understand what is the specific difference. Below I will give examples, explain them if possible. Thanks in advance.

setInterval:
For example I have a function which executes in 1 second, and there's a setInterval with an interval of 500ms. If I understand correctly, then the setInterval will not look at the amount of time required to perform the function. It will still run the function every 500ms.

And still I read somewhere that if the function takes longer to execute than the specified interval, the setInterval does not wait for specified delay and will start immediately.

Which of these versions is correct?

Recursive setTimeout:
About this method also is not entirely understood. Again an example: there is a function that runs for 1 second and interval c using setTimeout for example 500 MS. Whether to wait for the full implementation of the setTimeout function or the difference with setInterval that is guaranteed to function will be run every 500 MS?
March 25th 20 at 13:47
2 answers
March 25th 20 at 13:49
Solution
Call setTimeout in the end of the function when it is executed, and you will be happy.
I have a question about how they differ. Specific tasks now, no, I just want to know how these 2 methods actually work. Thanks for the answer. - vicente commented on March 25th 20 at 13:52
@vicente, setTimeout is called, works and dies. setInterval is called and it repeats until you kill. - Gerald commented on March 25th 20 at 13:55
@Gerald, I know what these functions do. I'm talking about the difference of a recursive setTimeout and setInterval. Not about what they do, I read the documentation, but that's about recursive setTimeout is not entirely clearly written, is asking. I ask again to read the question with examples, I think you will understand what I mean. - vicente commented on March 25th 20 at 13:58
@vicente, https://jsfiddle.net/Gerald_aleksei/wfjevxkt/
Look in the browser console, it should be understood - Gerald commented on March 25th 20 at 14:01
@Gerald, well, if I understand correctly, recursive setTimeout can say better than a simple setInterval, which guarantees that the function will be run every n seconds, which I pointed out. And setInterval can "eat" this time if the execution time of the function is greater than the specified interval? All right? - vicente commented on March 25th 20 at 14:04
@vicente, setInterval will not wait for worked a function or not - Gerald commented on March 25th 20 at 14:07
@Gerald, I understand. In this case, a recursive setTimeout to wait until the function is processed? If for example I pointed out zademidko 1 one second, and the function is handled by 10 seconds, the next cycle will start in one or ten seconds? - vicente commented on March 25th 20 at 14:10
March 25th 20 at 13:51
Some of the questions here considered.
https://habr.com/ru/post/462355/
Thanks for the reply. - vicente commented on March 25th 20 at 13:54

Find more questions by tags JavaScript