[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

Defining Functions

You're on a roll!

OK, now we've gotten familiar with JavaScript variables and values, let's get down to the real business, functions.

Here is the definition of a function called plusOne that adds one to its argument.

Here's code that uses the function to set the value of y.

The variable y is set to 11, because 10 + 1 is 11.

Functions can take more than one argument. Here is a function that takes two arguments.

Define a function named add that takes two arguments x and y, and returns the sum of x and y.


about news main