In this situation var foo;
Will “foo” point to somewhere in the memory that contains the value undefined
?
Does undefined
occupy memory in javascript?
Does undefined
mean that there is no memory address assigned to a specific label?
Advertisement
Answer
There’s two parts to your question. The variable itself and multiple copies of undefined
value.
First, variables can take space in memory. It’s not always known if they do take space since compilers can optimize your code in a way that they might not do so (or even straight up removed).
As of the other part of your question. Per the specification there’s only one undefined
value but the specification does not require the implementation to hold a unique representation of undefined
in memory. So any implementation can hold multiple copies of the value so long as the language semantics can be guaranteed.
Edit: Also, the specification does not specify its value representation in memory, so that’s also an implementation detail.