Functions are first-class citizens in JavaScript — they can be assigned to variables, passed as arguments, and returned from other functions. There are three ways to define them: function declarations (hoisted), function expressions (not hoisted), and arrow functions (=> concise, no own this). Scope Scope determines where variables are accessible. Global scope: accessible everywhere (minimize pollution). Function scope: variables inside a function stay inside. Block scope (let/const): variables inside {} stay in that block. Hoisting: var declarations and function declarations are moved to the top of their scope by the engine at compile time. Closures Closures are one of JavaScript's most powerful features. A closure is when an inner function retains access to variables from its outer…
Key Takeaways
Arrow functions have no own "this" — they inherit from outer scope.
Closures let inner functions access outer variables after execution.
var is hoisted and initialized; let/const are hoisted but not initialized.
Closures enable data privacy and factory functions.
Use .bind() to explicitly set "this" for regular functions.