NamsteJS - 1
NamsteJS - 1
Key Insights for [Namaste JavaScript 🙏 Course - JS Video Tutorials by Akshay Saini]
- JavaScript is considered both the most hated and the most loved programming
language in the world, reflecting a complex relationship among developers.
- Its popularity is high, yet many developers express frustration, often due to a lack
of understanding of its core concepts.
- This dichotomy emphasizes the need for deeper education and comprehension of
JavaScript fundamentals.
**Teaching Philosophy**
**Memory Component**
- This component, also referred to as the variable environment, stores all variables
and functions as key-value pairs.
- For instance, a variable defined as `let a = 10` would be stored in this component
as a key-value pair (`a: 10`).
- The memory component enables the JavaScript engine to keep track of variable
states and function definitions during execution.
**Code Component**
- Known as the thread of execution, this component is where the actual JavaScript
code is executed line by line.
- It ensures that each line of code is processed sequentially, meaning JavaScript will
only move to the next line after completing the current one.
- The code component is integral for maintaining the order of execution in JavaScript
programs.
- **Memory Creation Phase**: During this phase, JavaScript allocates memory for all
variables and functions, initializing them to `undefined`.
- **Code Execution Phase**: In this phase, JavaScript executes the code line by line,
replacing `undefined` with actual values as the program runs.
- Invoking a function triggers the creation of a new execution context, which also
has its own memory and code components.
- Each function invocation goes through the same two phases: memory creation
(allocating space for parameters and local variables) and code execution
(executing the function's code).
- When a function completes, its execution context is deleted, and control returns to
the previous context.
- The call stack ensures that execution contexts are managed efficiently, allowing for
nested function calls and maintaining the correct order of execution.
- This stack-based management helps JavaScript handle complex operations and
function invocations seamlessly.
- The call stack is also referred to by various names, including execution context
stack and runtime stack, underscoring its critical role in JavaScript execution.