the second is better because the first will have to get re-allocated after every call and will never disappear. whereas in the second, you use constant variables, which is a good pattern, but also the fact that it is local to the block of the arrow function, the GC can automatically know to de-allocate searchResults after the end of all searchResult(term) calls.
Agreed, plus the second one reads a little bit cleaner.
Ah! Yes, if it is outside function, it will remain there even after the function execution and won't be deallocated. Makes sense. Thanks.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.