From the course: Mastering Web Developer Interview Code

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

How does immutability work in JavaScript?

How does immutability work in JavaScript?

From the course: Mastering Web Developer Interview Code

How does immutability work in JavaScript?

- [Instructor] Immutability is a pretty important concept, and it means that an element is unchangeable. Now, its practical application in JavaScript is a little bit different than what some people think. So let's take a look at how it works. Now here's what immutability is not. In JavaScript version six, we have a new keyword called const. And you might think that that would create an unchangeable variable. And if you do try to change this variable once you've created it as a constant, then you would run into a problem either with your linter or with your console, depending on how you're doing things. But you would see that if we try to actually do that with an array, we would have a problem because, although we can't redefine this variable or this constant like this, with myArray equals five because we're changing the value of this array, this would throw an error. We can actually change the values of these elements…

Contents