Home | Mailing List | Blog | Tutorial Videos

Pass by Value

When setting variables equal to each other and then changing one of them, does it change the other? Consider the following code. What is logged?

let a1 = {
  name: 'Johnny',
  hobby: 'football'
};

let b1 = 'Lisa prefers Johnny';

let c1 = ['Denny', 'Michelle', 'Chris R'];

let a2 = a1;
let b2 = b1;
let c2 = c1;

a2.hobby = 'roofsitting';
b2 = 'Lisa prefers Mark';
c2[2] = 'Doggy';

console.log(a1.hobby);
console.log(b1);
console.log(c1[2]);

Select one: