Memoization in JavaScript Explained | How to Memoize | Javascript Memoization Tutorial in Easy way

preview_player
Показать описание
What is Memoization?
Memoization is an optimization technique where the results or output of an expensive function call are cached such that the result can be immediately returned the next time the function is called with the same input.

In simple terms, we have a function that consists of many lines of code and it takes a long time to execute it and give us the result. Also, we need to execute this function multiple times. We already know running this function just once takes a long time to give us the result. Now we need to run it multiple times which means we are making our code slow.

So, Is there a way where we can run our expensive function multiple times without making our code slow?

We will run this expensive function once for a particular input and then cache (store) the result of it. So that next time if the function is called with the same input then instead of running the expensive time consuming function we will simply take the result from the cache. And that’s how we prevent our code from being slow. This process is called memoization.

Connect with me:

#javascript #memoization #memoize
Рекомендации по теме