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:
- Define an outer function with local variables
- Define an inner function that references outer variables
- Return the inner function from the outer function (return)
- 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