# Javascript references and copies
Published on 14-04-2020

Good to know how Javascript takes care of reference primitive types

Primitive type:

const one = 1;
const copyOne = one;

 

Reference type for objects:

const person = {
  name: 'Loki'
};
const refPerson = person;

person.name = 'Tom';

console.log(refPerson.name);// prints 'Tom'

 

Same object, this time using the spread operator that makes a copy instead of a reference:

const person = {
  name: 'Loki'
};
const refPerson = {...person};

person.name = 'Tom';

console.log(refPerson.name);// prints 'Loki'

 

Fun fact: Loki is my cat.