[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

What's a Closure?

Ever wonder what closures are and how they work? You can learn about this advanced programming concept right now through interactive lessons in JavaScript.

Let's get started!

Here is an example of some JavaScript code. Doesn't it look pretty?

Don't worry, we're not just going to sit around and look at pretty code. We're going to be writing code!

Variables

Here's code that declares x is a variable, and then assigns x the value 5.

Now you try. Declare that y is a variable and then assign it the value 7. Click "submit" when you think you have it.

1:1

about news main