0

Looking the code-snippet:

var a;
var b;
var c;
var d;
a = undefined;
b = null;
d = 15;
d = undefined;

Now, I want to know the memory allocation (in terms of heap, stack or whatever) while writing this code.

For variables a, b, c, d -- what is the size of memory allocation? or in what order? also, is there any memory allocation for a, c, d? also, if we are setting value undefined for a or d -- what does it mean? does it mean that memory allocation is to be done and 'undefined' to be stored in it? or for d -- release 'memory-allocation' and do nothing?

Very confused. Anybody ... have some idea?

Note: Already seen

kindly don't mark duplicate.

Deadpool
  • 7,811
  • 9
  • 44
  • 88
  • 1
    The ECMAScript specification doesn’t contain such implementation details. As far it is concerned there is just “memory” and `null` and `undefined` are values like any other. If you wonder how a specific implementation does it, then you should include which one. According to the spec, all variables are created and initialized with `undefined`. – Felix Kling Jan 12 '20 at 14:55
  • Your titular question seems to be an exact duplicate of the second one you found. How did it not answer your question? – Bergi Jan 12 '20 at 16:08
  • "*also, is there any memory allocation for a, c, d?*" - why are you excluding `b` here, do you think `null` is somehow special? – Bergi Jan 12 '20 at 16:08
  • All the values in your question are primitives, and won't be allocated as a separate object on the heap. There is no memory allocation and deallocation other than for the `var` declaration itself. – Bergi Jan 12 '20 at 16:09

0 Answers0