...

/

Mistake: treating a value type as a reference type

Mistake: treating a value type as a reference type

Learn about the common mistake of treating a value type as a reference type.

We'll cover the following...

Suppose that the increaseAge method was erroneously implemented like this:

Press + to interact
var people = [
{ name: 'John Hill', age: 22 },
{ name: 'Jack Chill', age: 27 }
];
function increaseAge( age ) {
age += 1;
}
console.log( 'Before:', people[0].age );
increaseAge( people[0].age );
console.log( 'After:', people[0].age );

The age stays ...