end video

This lesson is only accessible in the paid version of the course.

Get access to all lessons 💫 price: 34.99$

If you already have an account click here.

§ What is memoization all about

In this video, we will introduce the concept of memoization in JavaScript and how it can be used to optimize the performance of functions that compute expensive results.

Memoization is a technique used to optimize functions by caching their results for specific inputs, so that the function does not have to recompute the same result for the same inputs again. This can greatly improve the performance of the function, especially for functions that are called multiple times with the same inputs.

Here is an example of memoization in JavaScript:

const cache = {};
function add(a, b) {
  const key = [a, b].toString();
  if (cache[key]) {
    return cache[key];
  }
  return cache[key] = a + b;
}

console.log(add(1, 2)); // Output: 3
console.log(add(1, 2)); // Output: 3

Memoization is used to speed up the execution of function by storing the results of function calls with specific inputs in a cache, so that the function does not have to recompute the same result for the same inputs again. This technique can be applied to any function that returns a value and has a small set of inputs.

questionnaire

Practice

Practice is the fastest way to learn knowledge permanently. I have prepared a small task for you related to the lesson.

Practice
discussion

Materials

Materials related to the lesson:
Files associated with the lesson

Materials

Next: Partial application(06:28)

To the lesson →