JavaScript Code Execution — Simplified
Published in
2 min readOct 8, 2023
JavaScript executes code in two phases:
1. Memory Creation Phase (Variable Setup):
- This is where JavaScript gets ready to work.
- It sets up space in memory for things like variables and functions.
- Variables are prepared but don’t have values yet; they are like empty boxes.
- Functions are stored in memory with all their instructions, like a recipe.
2. Code Execution Phase (Doing the Work):
- Now, JavaScript starts doing the actual tasks in your code.
- It works one step at a time, following the order of your code.
- When it sees a variable, it gives it a value.
- If there’s a function, it runs that function like a small program.
- After the function finishes, the result is saved, and the function’s stuff is removed.
Think of it like making a list of what you need to do (Memory Creation Phase) and then actually doing each task one by one (Code Execution Phase). When you have a recipe (function), you follow the steps in the recipe, and when you’re done, you put away the recipe and keep the dish you made.
Jai Hind, Vande Mataram 🇮🇳
Sounds too complicated? Read the Simplified Versions
- Pass by Value & Pass by Reference — Simplified
- JavaScript Code Execution — Simplified
- React Element — Simplified
Read more about React & JavaScript
- Understanding Callbacks in JavaScript
- Call Stack in JavaScript
- What is React
- Datatypes in JavaScript
- Variables in JavaScript
- Scope in JavaScript
- Hoisting in JavaScript
- Working of JavaScript