Skip to content

Instantly share code, notes, and snippets.

@dipakkr

dipakkr/blog.md Secret

Created October 21, 2020 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dipakkr/cf29e0d7920080260941af5193c04ab2 to your computer and use it in GitHub Desktop.
Save dipakkr/cf29e0d7920080260941af5193c04ab2 to your computer and use it in GitHub Desktop.

In today's post, I am going to write about how javascript works. We will throw some light on terminologies like Execution context, function level execution context, function invoking, and threads.

**Do you know what happens behind the scene when you run a javascript code? **

Let's take an example of the below code snippet.

https://gist.github.com/c8dc2561b8078487a6fdfd0fd9f0cc95

EC : Execution Context

When we run this code, here is what the Javascript engine does.

  • First, a Global Execution Context is going to be created.

  • Interpreter encounters call x(), and again a new EC is created for x.

  • Now the EC for x is created it will run the code line by line inside x.

  • Inside x, a new function call y() is invoked, it again creates an EC for y.

  • When y is finished running, it will back to EC of x, and variable t is assigned.

  • After x run is finished, it will be back to Global EC, and variable r is assigned.

  • Global EC finishes running and the program stops.

In tomorrow's blog, I will explain how the call stack works in Javascript. I would love to know your feedback on this blog.


Stay tuned - Follow me on Twitter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment