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
Copy file name to clipboardExpand all lines: README.md
+42Lines changed: 42 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -59,6 +59,10 @@ Top JavaScript interview questions
59
59
| 51 |[What is aync and await](#51-what-is-aync-and-await)|
60
60
| 52 |[What is the role of event.preventDefault()](#52-what-is-the-role-of-eventpreventdefault)|
61
61
| 53 |[What is the use of JSON.stringify()](#53-what-is-the-use-of-jsonstringify)|
62
+
| 54 |[How can you stop the setTimeout](#54-how-can-you-stop-the-settimeout)|
63
+
| 55 |[If Javascript is single threaded, how it supports asynchronous operations](#55-if-javascript-is-single-threaded-how-it-supports-asynchronous-operations)|
64
+
| 56 |[What is javascript scope](#56-what-is-javascript-scope)|
65
+
| 57 |[Difference between global scope and local scope](#57-difference-between-global-scope-and-local-scope)|
You can use the clearTimeout method. This method takes the id returned by setTimeout and cancels the timer.
812
+
```js
813
+
consttimerId=setTimeout(() => {
814
+
console.log('setTimeout is done');
815
+
}, 5000);
816
+
clearTimeout(timerId);
817
+
```
818
+
819
+
### 55. If Javascript is single threaded, how it supports asynchronous operations
820
+
JavaScript is single-threaded, means it can execute only one task at a time. Still, it supports asynchronous operations using the Web API provided by the browser.
821
+
822
+
823
+
### 56. What is javascript scope
824
+
In JavaScript, scope refers to the current context of your code. This context determines visibility and accessibility of variables, functions, and objects within a certain part of the code.
825
+
Generally, there are two types of scope in JavaScript - global scope and local scope.
826
+
827
+
### 57. Difference between global scope and local scope
828
+
**Global scope** - Global scope refers to the variables, functions, and objects that are defined outside of any function or block. They can be accessible from any part of the code.
829
+
```js
830
+
let name ="Surbhi";
831
+
functionprintName() {
832
+
console.log(name); // output ========> Surbhi
833
+
}
834
+
printName();
835
+
```
836
+
837
+
**Local scope** - Local scope refers to the variables, functions, and objects that are defined inside any function or block. They can be accessible only within the function or block where they are defined.
838
+
```js
839
+
functionprintName() {
840
+
let name ="Surbhi;
841
+
console.log(name); // output ========> Surbhi
842
+
}
843
+
printName();
844
+
console.log(name); // ReferenceError: name is not defined
0 commit comments