Timers in JavaScript

SetTimeout
This method calles a function after a number of milliseconds is executed only once.
                  
                       setTimeout(() => {
                         console.log('This is settimeout')
                       }, 2000)
                  
                
ClearTimeOut
This method to prevent the function from starting or stop execution.
                  
                       const myTimer = setTimeOut(() => {
                         console.log('This is settimeout')
                       }, 2000)

                       functionStopTimer(){
                         clearTimeout(myTimer);
                       }
                  
                
SetInterval
This method calls a function at specific interval in every milliseconds continuously till you dont call clearInterval method.
                  
                      setInterval(() => {
                        console.log('This is setinterval timer')
                       }, 2000)

                  
                
ClearInterval
This method is to stop execution.
                  
                    const myInterval = = setInterval(() => {
                         console.log('This is setinterval timer')
                       }, 2000)

                    functionStopInterval(){
                      clearInterval(myTimer);
                    }