I agree! The examples and definitions I’ve found online seem more clear-cut than actually working with shallow and deep copies.

This is my own speculation, but here it goes.

I believe this is a similar question to why “2 === 2” returns “true” in JavaScript, but “[2]===[2]” returns “false.” Googling “js === objects,” I learned that “Primitives like strings and numbers are compared by their value, while objects like arrays, dates, and plain objects are compared by their reference. That comparison by reference basically checks to see if the objects given refer to the same location in memory.”

So, primitives (or primitive values, or primitive data types) are the types string, number, bigint, boolean, null, undefined, and symbol. I assume that those objects are okay in the top level of a shallow copy, but any other types (I believe they’re all considered “objects” in JS, even arrays) are references, so an array of these would need a deep copy if you are changing values.

I hope this helps! Thanks for reading!

Written by

Full Stack Web Developer, former English as a foreign language teacher and volleyball coach. All views and opinions are my own.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store