Explain the concept of memoization in JavaScript.
Instruction: Define memoization and provide a use case where it can improve performance.
Context: This question tests the candidate's knowledge on optimization techniques in JavaScript, specifically memoization, and its application to enhance computational efficiency.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
Memoization reuses a previous result when the relevant inputs are unchanged. It is useful for an expensive pure calculation, but correctness depends on the cache key, equality rule, dependencies and lifetime.
This one-entry helper is for a unary function that does not depend on this or hidden mutable state...