Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
An anonymous function is a function that is not given an identifier. Anonymous functions are mostly used for passing functions as a parameter to another function.
<!DOCTYPE html><html lang="en"><body><script>
// function(){console.log('hi');}; // anonymous function, but no way to invoke it
// create a function that can invoke our anonymous function
var sayHi = function(f){
f(); // invoke anonymous function
}
// pass an anonymous function as parameter
sayHi(function(){console.log('hi');}); // log 'hi'
</script></body></html>