In easy words,


Closure is when a function reads or writes a variable that is declared outside of it.

If you declare any inner function within another function, the inner function is called closure.

It can access the variables created in the outer function or let’s say the main function.


When you’re declaring a variable inside a function, it is ONLY accessible WITHIN or INSIDE the function. Not to the outer elements. This is called scoping a function.


if (true) {
	const hmmOkay = "Hi";
	console.log(hmmOkay); // "Hi"

We won’t be able to access hmmOkay outside this function.

This is called a Block Scope

Similar Posts