课程: Mastering Web Developer Interview Code

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

How does immutability work in JavaScript?

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…

内容