A quick look at Mutability and Immutability of certain Data & Structure Types.

Another day, another dive into the world of JS basics. As I was writing my article last week on data & structural types I stumbled upon mutable data and immutable data. I was nearing the end of the article but realized that I went too far off on a tangent (which isn’t hard) that I deleted the section. Yet, the concept stuck with me.

JavaScript has some tricky gotchas that still get me to this day. (I accidentally wrote ‘…still git me to this day’ first and couldn’t figure out why Medium underlined it 🤦🏻‍♂️) One that I occasionally run into involves variables and values, more specifically, how the behavior of variables are affected depending on whether or not the value they reference is mutable or immutable.

First, let’s define mutable and immutable.

mutable: prone to change

immutable: not capable of or susceptible to change

A table showing Immutable vs. Mutable data/structural types in JavaScript

Immutable vs. Mutable data/structural types in JavaScript

Simple enough. Now, when it comes to JavaScript’s data & structure types they can all be thrown into one of these two categories. Primitive values are immutable and almost everything else is mutable.

#software-development #react #data-structures #javascript #software-engineering

JavaScript: Mutable vs. Immutable
2.25 GEEK