Difficulty: 5/10closures, memoization, performanceClosures can be used for memoization, a technique that stores the results of expensive function calls and returns the cached result when the same inputs occur again. This can significantly improve performance in recursive or repetitive calculations.CopyScenario Questions0-2 years experience1Write a tiny function that returns the nth Fibonacci number using a closure to memoize previous results. How does the closure keep the cache alive?2If you call that memoized Fibonacci function twice with the same argument, what will be logged if you added a console.log inside the original recursive calculation?3What would happen if you accidentally declared the cache variable outside the closure instead of inside it?Follow-up QuestionsHow would you verify that the cache is being hit versus recomputed?What problems can arise if the closure’s cache grows without bound?When might you choose a different caching strategy over a closure?Suggest Improvement