There are times in which we don’t want to run the code sequentially. For example, we want to run them at a set interval / after a period of time. JavaScript provides two functions for this:

setTimeout

console.log('Before setTimeout')
setTimeout(() => console.log('In setTimeout'), 1000)
console.log('After setTimeout')

/* This will print the following:
Before setTimeout
After setTimeout
In setTimeout *after a second*

You can see that setTimeout it's not a blocking call. It doesn't block the code.
The code continues running the following lines immediately.
The function given as the first parameter of setTimeout is run after 1000ms,
namely 1 second in this case. */

setInterval

setInterval(() => console.log('Outside is sunny'), 1000)
/* This will print the following:
Outside is sunny *after a second*
Outside is sunny *after a second from previous print*
Outside is sunny *after a second from previous print*
...

setInterval runs the function once at a set interval. In this case, each
second, it prints 'Outside is funny'.
*/

/* To stop an interval, you can save it in a variable and later call
clearInterval on that. */
const printingEach2Seconds = setInterval(() => console.log('Hi'), 2000)
...
clearInterval(printingEach2Seconds) // <- this will end the printing