DEV Community

Discussion on: Basic JavaScript Interview Questions

Collapse
 
grglldz profile image
Guiorgui

Closure is not necessarily a function, it can be any data type.
Closure is just a reference that is in the accessible scope, whose value comes from a scope that is not accessible.

Collapse
 
piotrlewandowski profile image
Piotr Lewandowski

"Closure is not necessarily a function, it can be any data type" not, exactly. According to MDN: "A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment)." (source: developer.mozilla.org/en-US/docs/W...)

Collapse
 
grglldz profile image
Guiorgui

That is not wrong. That's just one aspect of closures.

Thread Thread
 
piotrlewandowski profile image
Piotr Lewandowski

It's wrong when you phrase it like "JUST a reference that" ("just" suggests it's only that, not "one aspect of") when it's clearly not "just a" :) That's what I meant ;)

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

Wrong. A closure is the combination of a function and some references to either values or variables, depending on the language.

It's commonly simplified to just a function that has access to it's calling scope, because it effectively behaves that way in javascript and pretty much any other language that has them.