WTF is a closure?

On @tylerc6444 WTF is a closure lesson

Viktor asked,

"I know what the closure means but still the last example [1].map((a)) => a) is not quite clear.

> Its callback is a closure because it’s a nested function within a function that has access to its parent’s scopes.

It would be if Tyler has provided more explanation to the quoted statement with regard to the given example in my opinion."

Could someone provide some more context?

Maybe it would be more clear if the callback used a variable defined in the outer scope thus showing how it is a closure. So perhaps something like this:

const baseNum = 1;

const mappedValues = [1].map((a) => a + baseNum);

ya, that’s what I was thinking. It’s implicitly a closure, but we aren’t actually closing over anything in the code sample here so it doesn’t really register.

1 Like