JavaScript Advance Functions
In JavaScript, functions are more than just blocks of code. Because JS treats them as first-class citizens, you can assign them to variables, pass them as arguments, and even return them from other functions.
Higher-Order Functions (HOF)
A Higher-Order Function is a function that does at least one of the following: takes one or more functions as arguments, or returns a function as its result. Methods like map, filter, and reduce are native HOFs in JavaScript, abstracting iteration away and allowing developers to focus on the business logic inside the callbacks.
Closures & Lexical Scope
A Closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment). In simpler terms, a closure gives you access to an outer function's scope from an inner function, even after the outer function has completed execution. This is the foundation of data privacy and the Module Pattern in JS.
Recursivity
Recursion is when a function calls itself to solve a smaller instance of the same problem. A valid recursive function strictly needs a Base Case (to stop the infinite loop and prevent Stack Overflow) and a Recursive Case (the logic that pushes the problem towards the base case).
View Call Stack Transcript+
When a function executes, it is placed on the Call Stack. If it calls another function (or itself), that new execution context is pushed on top. In recursion, we build a tall stack until the base case is hit. Once hit, the stack "unwinds," returning values back down to the original caller.
