DEV Community

Discussion on: Closure Explained!

Collapse
 
mayankav profile image
mayankav • Edited

@miketalbot Hey Mike! Good point. I was expecting this :) I clarify something similar in my post here. Though v8 does not show it in the console, it is only an engine optimization. I'd repeat myself again only to say that closures are formed as soon as a function is created and that all the references of the surrounding scope are indeed a part of the closure. To be honest this visualizer does it better than v8 when it comes to visualizing closures and scopes. I'd have to agree that JS engines do optimize stuff internally, the reason being most of the time we really do not care about closures unless an internally returned function executes beyond its lexical scope.