Are Bindings and Variables Different in JavaScript?
Asked by
CreativeCoder42
I'm trying to understand the concept of bindings and variables in JavaScript. Are they the same thing, or is there a difference? I'd love to hear a detailed explanation about how these terms are used in the language.
Answers
Bindings and variables aren't exactly the same in JavaScript. A binding is about linking a name (or identifier) to a value in memory. When you declare a variable using let, const, or var, you're actually creating that binding. The variable itself holds the value assigned to that binding, so think of the variable as the data stored, while the binding is just the reference to that data.
Reply to this answer
So basically, in JavaScript, a binding defines a relationship where a variable can be linked to an input's value. Changing one often affects the other, but they serve different roles. The variable is a noun, while you can think of binding as the action of connecting things together.
Reply to this answer
Bindings refer to the connections between variables and their values. Like, when you do `const foo = 3;`, you're binding the value 3 to the identifier 'foo'. Itโs more about the relationship, rather than just being interchangeable with variables.
Reply to this answer
Iโve seen some confusion around the term โbindingโ in resources like Eloquent JavaScript, where it seems to be used interchangeably with โvariable'. Thatโs not exactly right; a binding is like an association of a variable name to a value, not the variable itself.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions