-
Notifications
You must be signed in to change notification settings - Fork 0
Asynchronous JS: How JavaScript Works?
Preeti Wadhwani edited this page Jun 12, 2021
·
10 revisions
-
The JS engine reads our code line by line with help of syntax parsers and creates a execution context (Can be more than one) which is responsible for running our code and does bit of
-
The base execution context is called Global (accessible anywhere, not inside any function) Execution context which has
- Global object -
windowobject in case of browser, it will vary in node env but there is always a global object - this keyword (which points to global object in this case)
- A link to the outer environment - which will be null in case of global execution context
- You code which it needs to run
That's why even when you don't put anything in the App.js file and run it in the browser, because we are running the Javascript file the execution context is created and we can access the window object in the browser console.
- Creation and Hoisting:
- In this step the JS setup the memory for variables (declared with var) and functions. Hence when we execution code and try to access variable which is declared later it still works as variable is already present in the memory and we can also call function which is declared later in the code
- Code Execution
- Runs the code line by line
- It keeps information about which function is currently getting executed and what to call next
- It is stack DS which keep adding functions as they gets called
- We can view
Call Stackby going intosource tab of Dev Toolsand putting breakpoint in the code
Only does one thing at any particular time or nothing
Then how we can handle things which takes time like API calls or save to Database?