File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed
Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change 1+ function a ( ) {
2+ console . log ( "a" ) ;
3+ }
4+ a ( )
5+ console . log ( "End" ) ;
6+
7+ // Callstack is in js Engine is in Browser
8+
9+ console . log ( ( "Start" ) ) ;
10+
11+ setTimeout ( function cb ( ) {
12+ console . log ( "Callback" ) ;
13+ } , 5000 )
14+ console . log ( "End" ) ;
15+
16+ console . log ( "Start" ) ;
17+ document . getElementById ( "clickMe" ) . addEventListener ( "click" , function cb ( ) {
18+ console . log ( "Callback" )
19+ } )
20+ console . log ( "End" ) ;
21+
22+ // 🟨Event Loop : Continuously monitor callstack and callback queue
23+ // ... If this call stack is empty and EventLoop sees this there is also a function waiting to be executed inside callbackQueue...
24+ // it just takes the function and put it inside the callstack... and callback method is quickly executed...
25+
26+ // Promises Mutation Observer
27+
28+ console . log ( "start" ) ;
29+ setTimeout ( function cbT ( ) {
30+ console . log ( "CB Netflix" ) ;
31+ } , 5000 ) ;
32+
33+ fetch ( "https://api.netflix.com" ) . then ( function cbF ( ) {
34+ console . log ( "CB Netflix" ) ;
35+ } )
36+ console . log ( "End" ) ;
37+
38+
39+ // Callstack : │ │
40+ // │ │
41+ // │ │
42+ // │ │
43+ // │ 2nd cbT => Run => Removed from callstack │
44+ // │ 1st cbF => Run => Removed from callstack │
45+
46+
47+ // Micro Task Que :│ cbF │ │ │ │ │ │ │ │ │ │ │ │ │ // prioritized 1st goes into callstack
48+
49+ // Callback Queue :│ cbT │ │ │ │ │ │ │ │ │ │ │ │ │ // after cbF
50+
51+
52+ // 1 Start
53+ // 2 End
54+ // 3 cbF
55+ // 4 cbT
You can’t perform that action at this time.
0 commit comments