You are developing a function that needs to maintain state between calls without using global variables. Which JavaScript feature would you utilize to achieve this?

  • Closures
  • Prototypes
  • Callbacks
  • Promises
You can utilize closures in JavaScript to maintain state between function calls without relying on global variables. A closure is a function that has access to variables from its outer (enclosing) function's scope, even after the outer function has finished executing. This allows you to create private variables and maintain state within the closure function.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *