bhylu.com

Advertisements

JS Data Types

Separate primitive values from object references. Copying a primitive copies the value; copying an object variable shares the reference.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

let count = 2;
let copy = count;
copy += 1;
console.log(count, copy);

What happens

The original stays 2 while the copy becomes 3.