FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript-Interview-Question/EventLoopOutput.js at master · namitmalasi/JavaScript-Interview-Question · GitHub
namitmalasi
/
JavaScript-Interview-Question
Public
Notifications
You must be signed in to change notification settings
Fork
5
Star
4
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScript-Interview-Question
/
EventLoopOutput.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
43 lines (32 loc) · 855 Bytes
Breadcrumbs
JavaScript-Interview-Question
/
EventLoopOutput.js
Copy path
File metadata and controls
43 lines (32 loc) · 855 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// The output of below code will be 0-8 but the terminal cursor does not get free.
// It means that that the output is displayed but the program kept running.
// It is because we have not cleared the interval.
let
a
=
true
;
let
count
=
0
;
setTimeout
(
(
)
=>
{
a
=
false
;
}
,
2000
)
;
setInterval
(
(
)
=>
{
if
(
a
)
{
console
.
log
(
count
++
)
;
}
}
,
200
)
;
// The output of the below code will infinite loop because the value a never becomes false.
// This happens due to Event loop.
let
a
=
true
;
let
count
=
0
;
setTimeout
(
(
)
=>
{
a
=
false
;
}
,
2000
)
;
while
(
a
)
{
console
.
log
(
count
++
)
;
}
// The output of below code will be 0-8 and the cursor gets free meaning that,
// the program has fiished executing or running.
let
count
=
0
;
let
id
=
setInterval
(
(
)
=>
{
console
.
log
(
count
++
)
;
}
,
200
)
;
setTimeout
(
(
)
=>
{
clearInterval
(
id
)
;
}
,
2000
)
;
Back
|
FazBrowse Home
|
New Git URL