0% found this document useful (0 votes)
28 views2 pages

Timing Function

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views2 pages

Timing Function

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

<!-- !

timing function -->

1. setTimeout

Definition:
- The setTimeout function is used to execute a function or a block of code
once after a specified delay (in milliseconds).

2. setInterval

Definition:
- The setInterval function is used to repeatedly execute a function or a block
of code at specified intervals (in milliseconds).

3. clearTimeout

Definition:
- The clearTimeout function is used to cancel a timeout that was previously
set with setTimeout. It prevents the function passed to setTimeout from
executing.

4. clearInterval

Definition:
- The clearInterval function is used to cancel a repeated action that was
previously set with setInterval. It stops the function passed to setInterval
from executing repeatedly.
// ! setTimeout()

console.log('start')
console.log('middle')

setTimeout(()=>{
console.log('this is setTimeout')
},5000)

console.log('end')

let hello = ()=>{


console.log('this is hello function')
}

setTimeout(hello,3000)

// ! setInterval()

setInterval(()=>{
console.log('i am setInterval')
},1000)

// ! clearInterval

let interval = setInterval(()=>{


console.log('hello')
},1000)

clearInterval(interval)

// ! clearTimeout

let timeout = setTimeout(()=>{


console.log('hello')
},1000)

clearTimeout(timeout)

You might also like