You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
where expression/function is the JavaScript code to run repeatedly at specified interval of time has elpased .
2042
+
2043
+
Main Difference
2044
+
2045
+
When you need to invoke a function/expression once after a specified duration use setTimeout() function.
2046
+
But, if you need to invoke a function/expression repeatedly at a specified interval of time, then you should use setInterval() function.
2047
+
2048
+
<div align="right">
2049
+
<b><a href="#">↥ back to top</a></b>
2050
+
</div>
2051
+
2011
2052
## Q. ***Why is JavaScript treated as Single threaded?***
2012
2053
2013
2054
JavaScript is a single-threaded language. Because the language specification does not allow the programmer to write code so that the interpreter can run parts of it in parallel in multiple threads or processes. Whereas languages like java, go, C++ can make multi-threaded and multi-process programs.
@@ -8743,44 +8784,3 @@ console.log(val.toString(16)); // A ==> Hexadecimal Conversion
8743
8784
<div align="right">
8744
8785
<b><a href="#">↥ back to top</a></b>
8745
8786
</div>
8746
-
8747
-
## Q. ***How setTimeout() and setInterval() are different from each other?***
8748
-
8749
-
```javascript
8750
-
//Syntax for setTimeout
8751
-
8752
-
functiondisplayMessage() {
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
-
functiondisplayMessage(){
8764
-
console.log('This message will be displayed after every 4s!') ;
0 commit comments