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

Variables and Values

Congratulations! You passed your first exercise. You are awesome.

To save typing, you can declare variables and give them initial values all on one line. This one-liner declares the variable fish and sets it to the value 42.

JavaScript has more values than just numbers. Here are some more examples.

In case you missed it, strings can use either single or double quotes. That's handy if you need a quote inside a string.

Declare a variable colors that has a value that is an array with 3 strings that are color names. The first element of the array should be "blue". The second element of the array should be "red". Get creative for the third element.


about news main