Member-only story

Interviewer: What is a Closure in JavaScript?

Here’s how to answer this question and secure your job.

Afan Khan
12 min readAug 2, 2023

--

If you’re a non-premium user, click here to read this article for free. If not, continue reading.

Source: INext

Most developers get confused with or fail to understand the concept of Closures in JavaScript because of its complexity. Many developers point to Closures as one of the most challenging concepts in JavaScript to fully understand and implement.

Nevertheless, let me simplify Closures for you to understand it thoroughly in this article, and then you can explain it to others in your development space.

To understand the concept of Closures, I suggest you first grasp a solid understanding of the Call Stack, Execution Contexts, Variable Environments, Scope Chains, and Lexical Scoping.

What are closures?

By definition, Closures are a magical part of the browser’s JavaScript engine that remembers the variable environment of the Execution Context in which its connected function was born.

It can easily recall the variables of the surrounding environment within which it got created. For the same reason, some people define Closures as a function since it enables a function to access those local variables of a surrounding…

--

--

Afan Khan
Afan Khan

Written by Afan Khan

I create tools for innovators and problem solvers to bring forward new and impactful technological advancements.

No responses yet