Variables are a complete "illusion"

META

Activist
SUPREME
MEMBER
Joined
Mar 1, 2026
Messages
118
Reaction score
378
Deposit
0$

What is a variable?​

Let's recall the concept of "variable." How do you usually construct a complex definition of this term? Here are examples of how the concept is presented to you on a silver platter:

  • it is a storage of data, values;
  • it is a named area in memory
  • it is a box that has a name in which the value is stored;
  • This is a value that is stored in a cell with a specific name;
  • and others...

Well, now why are there no variables? :D

As you can see from the definitions above, all of this sounds very simple and understandable from the perspective of human logic, but not from the perspective of computer logic (which could be philosophized about forever). Now just ask yourself: is this really a "data warehouse" or a "box with a value," or was it all deliberately invented by some IT giants to simplify the terminology and mislead you, both beginners and professionals? Many of you will say yes, yes, it really is, it is definitely a "storage," but only a small number will say, "What kind of nonsense have you written here??"

In languages like C, C++, and JavaScript, the concept of a variable DOESN'T EXIST by nature! More accurately, the concept is floating around, but it exists more as an abstraction.
If you delve into the official English-language standard of each programming language (for example, those I listed above), you'll see that the concept of a variable is not mentioned there, or is simply referred to as an indirect "conventional term." You'll immediately ask, "How can that be?" So what happens when you say var x = 5; or int x = 5;?

Let me explain using JavaScript as an example. According to the official ECMAScript specification , you create an identifier x. But that's not quite right, of course. More accurately, if you rely directly on the specification, it's an IdentifierReference (abbreviated IdRef, ref means reference) - x is like a reference to an identifier. I'll read you a line from the specification right now:

"IdentifierReference: Identifier" - then Ascending is just a name you specify. But what is this name? What does it refer to?

When you wrote var x = 5;

You created x, which is precisely this IdentifierReference and refers to (points to) a binding BindingIdentifier , which in turn is a direct connection between this x and a certain value 5. What does the engine do? The engine calls the internal abstract operation ResolveBinding("x") to determine what "x" is. It turns out that "x" in this case doesn't store the value 5, but rather references it through a binding.

How does ResolveBinding work?​

ResolveBinding is an abstract operation described in the official ECMAScript specification. According to the specification, the operation takes a name (for example, in our case, "x") and, optionally, an environment (environment, or env for short), and returns either a value reference or an error. If env is not specified, the so-called current environment is taken from the current execution context—the LexicalEnvironment (LexEnv). In fact, LexEnv, from a human (not computer) perspective, is a table that already stores all the names and their values in the current scope.

from the specification

from the specification
Let's look at the picture;

  • so if env is not passed or is undefined then it goes
    • The current scope is set in env.
  • Further confirmation that env is actually a scope and not just anything:D
  • Next there is a check for strict mode.
  • and then comes the call to GetIdentifierReference with env, name, strict.
In general, we can go further and understand how GetIdentifierReference works :D

from the specification

from the specification
Above, we found out that GetIdentifierReference takes exactly three arguments: the environment (env), some name (for example, for us it is "x") and the strict mode flag.

  • so if env is null then
    • return record (x type could not be determined)
    • It's also worth noting that in strict mode this will likely cause a RefError, and in non-strict mode it will create a global identifier.
  • Next, this "has binding" is a question to env - "Do you have a binding to name?"
  • if there is: return the record Ref.. Record
  • If not, we look in the outer environment. There, GetIdentifierReference is called recursionally—that is, it goes up the scop chain until it finds the required identifier or reaches null.

Let's go to MDN:D and check ourselves:D

mdn link: https://developer.mozilla.org/ru/docs/Learn_web_development/Core/Scripting/Variables

about variables in mdn

about variables in mdn
Let's break down what they wrote here: firstly, as you've already figured out, a variable isn't a container, it's more of an abstraction or, as I call it, a "programmer's illusion." MDN says that name is a variable that stores the name from prompt, and then there's alert() in their example. Let's start with the fact that prompt and alert don't actually relate directly to the JavaScript language, but I'll cover that in another article. The correct way to say it is that name is an identifier that refers to some "name" value received from prompt. And there's no such thing as "storing it in a variable." Forget it, just forget it!!! This is a simple example of how the giant MDN is simply trying to convey everything in simple terms, simplifying what absolutely cannot be simplified. This is a fundamentally incorrect explanation and application of what is written in the official JavaScript language specification in ECMAScript.
 
Top Bottom