Primitive (values) vs Objects (references)

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. (aka it’s stored elsewhere to preserve memory space and the variable is just a link to it).
  • Reference value stored in the variable location is a pointer to a location in memory where the object is stored.
  • 5 Primitive types: Undefined, Null, Boolean, Number, or String.  Anything else is an object.

The Basics:

Objects are aggregations of properties. A property can reference an object or a primitive.

Primitives are values, they have no properties.

Some Examples:

screen-shot-2017-02-22-at-9-37-22-pm

Advertisements
Primitive (values) vs Objects (references)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s