[sign in]

What's a Closure?

  1. What's a Closure?
  2. Variables and Values
  3. Defining Functions
  4. Side Effects
  5. Functions are Values
  6. Returning Functions
  7. Function Scope
  8. Nested Functions
  9. Stateful Closures
  10. Private Data
  11. Asynchronous Callbacks
  12. Continuation Passing

Functions are Values

Functions are values in JavaScript. Just like 5 is a value that you can assign to a variable, the function that returns its input plus one is a value that you can assign to the variable addOne.

Because functions are values, you can do lots of cool things with them. You can put them in a list.

Because functions are values, you can pass functions as arguments and return them from other functions. Here is a definition of callTwice that takes a function f as an argument and invokes it twice in a row.

Define a function named applyTest that takes two arguments, a function f and an input x. Your function should return a list that contains x, the function f on the input x, and the function f on the input 0.

1:1

about news main