Function Expressions
Nicholas C. Zakas · 2015
This chapter talks about function expression characteristics, recursion with functions, and private variables using closures. Function expressions are useful tools in JavaScript programming. They allow truly dynamic programming where functions need not be named. These anonymous functions, also called lambda functions, are a powerful way to use JavaScript functions. Function expressions are different from function declarations. With no definitive way to reference a function, recursive functions become more complicated. Recursive functions running in nonstrict mode may use arguments.callee to call themselves recursively instead of using the function name, which may change. Closures are created when functions are defined inside other functions. Behind the scenes, the closure's scope chain contains a variable object for itself, the containing function, and the global context. Using closures, it is possible to mimic block scoping in JavaScript, which does not exist natively. Closures can also be used to create private variables in objects.