Image credit

Introduction

Unlike other languages, one of the most confusing mechanisms in JavaScript is the keyword. It’s a special identifier that is automatically defined in the scope of every function, but what it exactly refers to sometimes troubles even the seasoned JavaScript developers. JavaScript’s mechanism isn’t actually that difficult to understand, but developers quote it as complex or confusing in their own mind without actually trying to understand it.

Now you might be wondering if the mechanism is so confusing, even to seasoned JavaScript developers, why it’s even useful? Is it more trouble than it’s worth? …


JavaScript closures is one of the concepts that many people starting with JS struggle with. In this article I’ll try to explain Closures in simple terms using easy to understand code snippets.

What is Closure?

  • In simple words, Closure is when a function remembers & continues to access variables from outside its scope, even when the function is executed in a different scope.
  • Closure is actually a live link, preserving access to the full variable itself.
  • Closure can not only be used to access variable for reading its value but it can be updated or re-assigned as well.

Still couldn't understand clearly what Closure really is?

Let’s have a look at…

Rohit Sharma

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store