HomeToolsAbout

Array Memory Reference

Memory Reference

Each array has its own memory reference

  • Arrays are distinct even with identical content
Array("asdf") === Array("asdf") // false

Strict Comparison

=== is a strict equality, not identity operator.

  • Strict equality operator on object and array are checked to see if they point/reference to the same memory address.
  • Since every new object/array has its own memory address, two arrays or any two objects created cannot be equal even if the contents of the two arrays or objects are identical.

Identical looking object/array content doesn't mean they are pointing to the same memory

Shallow vs Deep Copy [link]

Shallow copy creates another reference to the same object.

Deep copy creates another object with exact values copied (hence, not referencing the original object)

Shallow Copy

Shallow Copy stores the references of objects to the original memory address.

  • Reflects changes made to the new/copied object in the original object.

Stores the copy of the original object and points the references to the objects.

Deep Copy

Stores copies of the object’s value.

  • Doesn’t reflect changes made to the new/copied object in the original object.

Stores the copy of the original object and recursively copies the objects as well.

AboutContact