Memoization Flashcards
What is memoization?
It’s a technique where the results of expensive function calls are cached and returned when the same inputs occur again.
How do you implement memoization in JavaScript?
You can store the results of a function call in a cache object and return the cached value if the same inputs are encountered again.
What is a cache object in memoization?
It’s a data structure used to store previously computed results of a function. It can be implemented using a plain JavaScript object or a Map object.
What is the benefit of using memoization?
It can significantly improve the performance of functions that are called with the same inputs repeatedly, by avoiding expensive computations and returning cached results instead.
What is a potential downside of using memoization?
It can consume more memory if the cache object grows too large, especially if the function being memoized accepts many different input values.