DEV Community

dannohh
dannohh

Posted on

# Tools of the Trade

A 'closure' is a function that has access to it's outer function's variables and methods. It can also access variables and methods within it's own scope and of course, the global ones as well! This means that JS callbacks are also closures.

When using callbacks, I like to imagine that when the callback function is complete, it allows the higher-order function to close out. Much like when we're done using a saw to cut an angle in some wood, we close out the task of cutting when the wood is no longer whole and the saw has stopped moving, then we move on to the next promise of screwing it to another piece of wood 🛠️! ...or maybe painting is the next task 🎨. Either way, we've closed and are ready for the next!

Top comments (0)