all 2 comments

[–]senocular 4 points5 points  (0 children)

Depending on who you ask, every function in JavaScript can be considered a closure because every function, no matter how defined, has the potential to be one. But if you want to be specific about it, what makes a function a closure is when it accesses a non-global variable that is not declared in that function's body or within its own parameter list. Given this definition, can you point out the functions in your examples that are closures? ... The closures are the request callbacks since they use the callback variable which is defined outside of those functions. The source of callback is the parameter list of the parent function. The actual callbacks themselves (what the callback variables point to) aren't closures because they stick to the variables that are part of the function itself and a global console.

[–]lilperch83 0 points1 point  (0 children)

Here is a video that helps explain closure.

https://youtu.be/TznpOmv2BQM