I read a book called “Professional Javascript for web developer” and it says: “Variable is assigned by Reference value or Primitive Value. Reference values are objects stored in memory”. And then it says nothing about how Primitive value is stored. So I guess it isn’t stored in memory. Based on that, when I have a script like this:
var foo = 123;
How does Javascript remember the foo variable for later use?
A
variablecan hold one of two value types:primitive valuesorreference values.Primitive valuesare data that are stored on the stack.Primitive valueis stored directly in the location that the variable accesses.Reference valuesare objects that are stored in the heap.Reference valuestored in the variable location is a pointer to a location in memory where the object is stored.Undefined,Null,Boolean,Number, orString.The Basics:
Objects are aggregations of properties. A property can reference an
objector aprimitive.Primitives are values, they have no properties.Updated:
JavaScript has 6 primitive data types: String, Number, Boolean, Null, Undefined, Symbol (new in ES6). With the exception of null and undefined, all primitives values have object equivalents which wrap around the primitive values, e.g. a String object wraps around a string primitive. All primitives are immutable.