JavaScript Functions & Memory Management

🚀 Day 6 of Learning JavaScript Today I explored one of the most important core concepts in JavaScript — Functions and how JavaScript handles memory behind the scenes ✅ Functions in JavaScript: → Functions don’t need return type declaration (JS is loosely typed) ▫️Syntax: function name(parameters){ // function body return value } ✅ Types of Functions: 🔹Function Declaration 🔹Function Expression 🔹Arrow Functions (=>) 🔹IIFE (Immediately Invoked Function Expression) ✅ Execution Context & Memory Perspective: → When a JavaScript program starts, Global Execution Context (GEC) is created in the stack. → It stores all declarations (variables and function signatures) that exist outside function blocks. 🔸Function Execution: → Every time a function is called, it creates its own execution context on the stack. → This is where local variables defined within that function are allocated memory. 🔸Function Scope: → Variables created within a function (e.g., let c) are function scoped. → They cannot be accessed outside the function. → If you try to access them, it results in a "ReferenceError", as the variable is not defined in GEC. 🔸Memory Deallocation: → Once a function completes execution and control moves to the next line, its execution context is deallocated (removed from the stack). → This also removes its local variables, which is why they cannot be accessed after the function call. → Finally, the call stack is cleared once the entire program finishes execution. Thank you to Harshit T sir. #webdevelopment #JavaScript #Learning #frontend

To view or add a comment, sign in

Explore content categories