fancymatt
← works

· course

Arrays and Objects in JavaScript

An intermediate Pluralsight course on how arrays and objects actually work in JavaScript, for developers who already use them every day.

Arrays and Objects in JavaScript
Exhibit

A Pluralsight course on how arrays and objects actually work in JavaScript, for developers who already use them every day. Intermediate level, 1h 48m. One of the four courses I wrote for Pluralsight.

Arrays and objects are everywhere in JavaScript, so most people learn them by using them. That works until something does what the habit can't explain: a copy that turns out not to be a copy, two identical objects that aren't equal, an array with holes in it. This course is about the reasons behind those details.

objects first

The course starts with objects, because everything after depends on them. What an object is, how to create one, and what a prototype is, including setting one directly with Object.create. Then properties: creating, accessing, deleting, protecting and enumerating them.

Next is what happens behind the scenes. Objects are reference types, which is why comparing and cloning them takes more care than it seems like it should, deep clones included. Then functions stored as properties, scope inside objects, and the object wrappers JavaScript puts around primitives.

Arrays come third, and the first thing that module says is that arrays are objects. Creating them and telling them apart from other objects. Adding and accessing elements, cutting arrays up, putting them together, cloning and sorting them. Sparse arrays, and the structures that sit next to arrays: Maps, Sets and typed arrays.

The last module is iteration. It starts with the for loop, then moves to the methods that summarize, search and map an array, which is where JavaScript starts to look functional.

That order does most of the work. By the time arrays come up, a lot of their strange behavior has already been explained, because it's object behavior. An array that changes when you edit a second variable is a reference type doing what reference types do.