Skip to content

Commit

Permalink
Update event_loop_explained.js
Browse files Browse the repository at this point in the history
  • Loading branch information
kunalpanchal authored Apr 29, 2021
1 parent 55573b7 commit a4c8bc4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tricky/event_loop_explained.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/*
CASE 1 Explanation
When we run the given loop,we see that hello would be printed 100000 times first and only after that the console within the setTimeout gets printed.Also the fact that if it did take 10 seconds to run the for loop and to print "hello" 100000 times then the first 10 "inside setTimout" would be printed suddenly and after that it would print after 1 sec each.This is due to the fact that after the setTimeOut was completed for first few,they were pushed to the event loop and it waited till the call stack was empty (printing hello 100000 times), and only after that "inside setTimeout started to print".
When we run the given loop,we see that hello would be printed 100000 times first and only after that the console within the setTimeout
gets printed.Also the fact that if it did take 10 seconds to run the for loop and to print "hello" 100000 times then the first 10 "inside setTimout"
would be printed suddenly and after that it would print after 1 sec each.This is due to the fact that after the setTimeOut was completed for
first few,they were pushed to the event loop and it waited till the call stack was empty (printing hello 100000 times), and only after that
"inside setTimeout started to print".
Just run the code in the browser console for clarity.
*/
Expand Down

0 comments on commit a4c8bc4

Please sign in to comment.