Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@
| 349.|[Explain types of Memory Leaks in JavaScript?](#q-explain-types-of-memory-leaks-in-javascript)|
| 350.|[How accidental closures might cause memory leaks in IE?](#q-how-accidental-closures-might-cause-memory-leaks-in-ie)|
| 351.|[How to convert Decimal to Binary in JavaScript?](#q-how-to-convert-decimal-to-binary-in-javascript)|
| 352.|[How setTimeout() and setInterval() are different from each other ?](#q-how-setTimeout()-and-setInterval()-are-different-from-each-other)|


<br/>

Expand Down Expand Up @@ -8741,3 +8743,44 @@ console.log(val.toString(16)); // A ==> Hexadecimal Conversion
<div align="right">
<b><a href="#">↥ back to top</a></b>
</div>

## 335Q. ***How setTimeout() and setInterval() are different from each other ?***

```javascript
//Syntax for setTimeout

function displayMessage() {
console.log('This message will be displayed only once after 4s!') ;
}

setTimeout(displayMessage, 4000);

```

```javascript
//Syntax for setInterval

function displayMessage(){
console.log('This message will be displayed after every 4s!') ;
}

setInterval(displayMessage, 4000) ;

```

Usage : setTimeout( function/expression, timeout, param1, param2, ... ) ;

where expression/function is the JavaScript code to run after the timeout milliseconds have elapsed. The params are optional.

Usage : setInterval ( function/expression, interval, param1, param2, ... );

where expression/function is the JavaScript code to run repeatedly at specified interval of time has elpased .

Main Difference

When you need to invoke a function/expression once after a specified duration use setTimeout() function.
But, if you need to invoke a function/expression repeatedly at a specified interval of time, then you should use setInterval() function.

<div align="right">
<b><a href="#">↥ back to top</a></b>
</div>