Is every function a closure?

Yes, exactly. As you’ve identified, every function in JavaScript is a closure over at least one context: The global context. That’s how/why global variables work in JavaScript.

We don’t normally call them closures unless they close over some other context and actually make use of the fact that they do, but you’re quite right that at a technical level, they all are.


Every function closes over program’s global variables (basically in every mainstream language, be it javascript/c/c+/whatever).

I wouldn’t generalize that far, no. Different languages have different ways of implementing global variables. Whether functions in those languages are all “closures” is probably open for debate, so I’ve restricted my answer above to JavaScript.

Leave a Comment