Put in order · JavaScript and TypeScript course · Module 2: Functions, Arrays and Objects

Steps of Creating a Closure

Arrange the steps of creating and using a closure in JavaScript:

Items to put in order

  • Call the outer function and store the result in a variable
  • Call the returned function - it has access to outer variables thanks to the closure
  • Define an outer function with local variables
  • Return the inner function from the outer function (return)
  • Define an inner function that references outer variables
Show the answer

Correct order:

  1. Define an outer function with local variables
  2. Define an inner function that references outer variables
  3. Return the inner function from the outer function (return)
  4. Call the outer function and store the result in a variable
  5. Call the returned function - it has access to outer variables thanks to the closure