Last update:   29-10-2021

Primitives vs. Objects

One of the fundamental differences of objects vs primitives. Objects are stored and copied by reference.


We have two independent variables, each one is storing the string "Hello!".
let message = "Hello!";

let phrase = message;


With objects we have two variables, each one with the reference to the same object. Here, the object is stored somewhere in memory, and the user has a “reference” to it. When an object variable is copied – the reference is copied.
let user = { name: 'John' };

let admin = user; = 'Pete'; 

console.log(;  // Pete - from the user reference
Not Equal    (2/3)

Not equal

Here two independent objects are not equal, even though both are empty.
let a = {};
let b = {}; // two independent objects

alert( a == b ); // false

Make a duplicate of the user (no reference). Hint: copy user properties
let user = {
  name: "John",
  age: 30

let clone = {}; // new empty object

// your code here

// your code END = "Pete"; // changed the data

console.log(; // John - from the original object


        A B C D E F