Primitive value vs Reference value

前端 未结 7 1687
执念已碎
执念已碎 2020-11-22 08:23

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 st

7条回答
  •  误落风尘
    2020-11-22 08:32

    A variable can hold one of two value types: primitive values or reference values.

    • Primitive values are data that are stored on the stack.
    • Primitive value is stored directly in the location that the variable accesses.
    • Reference values are objects that are stored in the heap.
    • Reference value stored in the variable location is a pointer to a location in memory where the object is stored.
    • Primitive types include Undefined, Null, Boolean, Number, or String.

    The Basics:

    Objects are aggregations of properties. A property can reference an object or a primitive. 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.

提交回复
热议问题