Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c1de456

Browse files
Question-Answer-54-57
1 parent 1401a40 commit c1de456

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

‎README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ Top JavaScript interview questions
5959
| 51 | [What is aync and await](#51-what-is-aync-and-await) |
6060
| 52 | [What is the role of event.preventDefault()](#52-what-is-the-role-of-eventpreventdefault) |
6161
| 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) |
6266

6367

6468
### 1. What is JavaScript
@@ -802,3 +806,41 @@ const obj = { firstname: "Surbhi", lastname: "Dighe" };
802806
const jsonString = JSON.stringify(obj);
803807
console.log(jsonString); // output ========> {"firstname":"Surbhi","lastname":"Dighe"}
804808
```
809+
810+
### 54. How can you stop the setTimeout
811+
You can use the clearTimeout method. This method takes the id returned by setTimeout and cancels the timer.
812+
```js
813+
const timerId = 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+
function printName() {
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+
function printName() {
840+
let name = "Surbhi;
841+
console.log(name); // output ========> Surbhi
842+
}
843+
printName();
844+
console.log(name); // ReferenceError: name is not defined
845+
846+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /