DEV Community

Discussion on: Understand Memoization in 5 Minutes

Collapse
kurtiev profile image
Fikret Kurtiev

Hi Nick!
Thanks for the post!
Could someone clarify me please, why "const results = {}" is stays the same on each call of method "memoize()"? I thought it will be created each time on call "memoize()" and this approach wouldn't work, but seems like it works! :)

Thanks.

Collapse
airmind profile image
Alex Ágreda

It's because of closures & lexical scoping, Fikret

developer.mozilla.org/en-US/docs/W...

Collapse
kurtiev profile image
Fikret Kurtiev

Yeah... i didn't notice that "memoize()" called only once.