Skip to content

Commit 691539b

Browse files
Merge pull request learning-zone#4 from NegiAkash890/master
Updated Question Section
2 parents 0c34056 + fd36122 commit 691539b

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@
348348
| 349.|[Explain types of Memory Leaks in JavaScript?](#q-explain-types-of-memory-leaks-in-javascript)|
349349
| 350.|[How accidental closures might cause memory leaks in IE?](#q-how-accidental-closures-might-cause-memory-leaks-in-ie)|
350350
| 351.|[How to convert Decimal to Binary in JavaScript?](#q-how-to-convert-decimal-to-binary-in-javascript)|
351+
| 352.|[How setTimeout() and setInterval() are different from each other ?](#q-how-setTimeout()-and-setInterval()-are-different-from-each-other)|
352+
351353

352354
<br/>
353355

@@ -8741,3 +8743,44 @@ console.log(val.toString(16)); // A ==> Hexadecimal Conversion
87418743
<div align="right">
87428744
<b><a href="#">↥ back to top</a></b>
87438745
</div>
8746+
8747+
## 335Q. ***How setTimeout() and setInterval() are different from each other ?***
8748+
8749+
```javascript
8750+
//Syntax for setTimeout
8751+
8752+
function displayMessage() {
8753+
console.log('This message will be displayed only once after 4s!') ;
8754+
}
8755+
8756+
setTimeout(displayMessage, 4000);
8757+
8758+
```
8759+
8760+
```javascript
8761+
//Syntax for setInterval
8762+
8763+
function displayMessage(){
8764+
console.log('This message will be displayed after every 4s!') ;
8765+
}
8766+
8767+
setInterval(displayMessage, 4000) ;
8768+
8769+
```
8770+
8771+
Usage : setTimeout( function/expression, timeout, param1, param2, ... ) ;
8772+
8773+
where expression/function is the JavaScript code to run after the timeout milliseconds have elapsed. The params are optional.
8774+
8775+
Usage : setInterval ( function/expression, interval, param1, param2, ... );
8776+
8777+
where expression/function is the JavaScript code to run repeatedly at specified interval of time has elpased .
8778+
8779+
Main Difference
8780+
8781+
When you need to invoke a function/expression once after a specified duration use setTimeout() function.
8782+
But, if you need to invoke a function/expression repeatedly at a specified interval of time, then you should use setInterval() function.
8783+
8784+
<div align="right">
8785+
<b><a href="#">↥ back to top</a></b>
8786+
</div>

0 commit comments

Comments
 (0)