DEV Community

dannohh
dannohh

Posted on

1

# 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)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay