What is the function prototype and call stack?
Answer
Every JavaScript function is an object and has a prototype property (distinct from the function's own [[Prototype]]). When a function is used as a constructor with new, the newly created object's [[Prototype]] is set to the constructor's prototype property. So methods added to Function.prototype are available on all function objects. The call stack is a data structure (LIFO) that tracks the execution of function calls. When a function is called, a new frame is pushed onto the stack containing the function's local variables and execution context. When the function returns, its frame is popped. Example: calling a() which calls b() which calls c() creates a stack: global → a → b → c. When c() returns, the stack becomes: global → a → b. A stack overflow (Maximum call stack size exceeded) occurs when recursion goes too deep without a base case — the stack fills up. The stack is visible in DevTools when an error is thrown — the stack trace shows the call chain.
Previous
What is the difference between Array.find() and Array.filter()?
Next
What is prototype pollution in JavaScript?