An anonymous function is a function without a name. It is usually defined inline, directly where it is used, rather than assigned to a variable or referenced later. This makes it useful for short, context-specific behavior that runs once. section 10.12 section 12.5
Distinguish the three common ways to define a function:
- Define and name it globally when many parts of a program may reuse it. section 10.12
- Define and name it locally when it needs local values but should remain unavailable outside its scope. section 10.12
- Define it inline as an anonymous function when the behavior is short, contextual, and needed once. section 10.12
Passing behavior to map()
var friendGreetings = map(friendsNames, function(name) { return "Hello, " + name; }); The function receives one array element at a time. Naming the argument name communicates that expectation, while the inline definition keeps this one-use behavior beside map(). section 12.4 section 12.5
withLogging(function() {
saveUserData(user);
});
See an anonymous function passed directly to withLogging(), contrasted with named and locally assigned alternatives. section 10.12

















