Javascript interview questions and answers #shorts #react #javascript #interview

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

My solution was to declare the array outside the function. lol. But your solution is great too

krishnanspace
Автор

For others saying create an array outside
That's not a perfect solution because that array is accessible everywhere because it's in global scope
Whereas with closure that array will only be accessible to the child function
A closure is a function that creates its own scope and returns another function along with that scope

truthShallPrevailRRVS
Автор

Thanks for sharing
Why dont just return 0 so no array would be created😂

trongquocnguyen
Автор

Amazing
I know about closures but not about use cases like this

jatthundeaaaaa
Автор

var newArray = null;

function expensiveFunction(index) {
if (newArray == null) {
newArray = new Array(100).fill('0');
}
return newArray[index];
}

animuspexus
Автор

i think u yourself making it confusing just simply define it outside..the fuction ...it would be more predictable

BhideSvelte
welcome to shbcf.ru