Be a better Javascript programmer by understanding the difference between deep copy and shallow copy.

Using the = operator to copy an array or an object results in a shallow copy. Modifying the shallow copy also modifies the original and vice versa. If this is not what you want, make a deep copy. To deep copy an array:

var array2 = array1.slice(0);

To deep copy an object:

var obj2 = {};
for (var propName in obj1) {
obj2[propName] = obj1[propName];
}

Primitive types (strings, numbers, booleans) are always deep copied.

When passing arguments to a function, arrays and objects are passed by reference, while primitive types are passed by value.

Loading more stuff…

Hmm…it looks like things are taking a while to load. Try again?

Loading videos…