Function passing

In functional programming languages, functions are first-class citizens. Functions can be assigned to variables and passed around just like you would with any other variable. This is not entirely a foreign concept. Even languages such as C had function pointers that could be treated just like other variables. C# has delegates and, in more recent versions, lambdas. The latest release of Java has also added support for lambdas, as they have proven to be so useful.

JavaScript allows for functions to be treated as variables and even as objects and strings. In this way, JavaScript is functional in nature.

Because of JavaScript's single-threaded nature, callbacks are a common convention and you can find them pretty much everywhere. Consider ...

Get Mastering JavaScript Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.