From the course: Learning Functional Programming with JavaScript ES6+

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Ensuring immutability with ESLint

Ensuring immutability with ESLint

- [Instructor] So I talked in a previous video about the importance of immutability in functional programming. Immutability allows us to avoid the many bugs that occur in computer programs as a side effect of state change. It also means that we don't have to worry about using private variables to avoid changes coming from unexpected places, since we simply can't make changes to any piece of data. That being said, if we want to ensure complete immutability in JavaScript, there's something we need to keep in mind. While using the const keyword prevents us from directly changing the value of a piece of data, for example, if we say const X equals five, we can't simply say X equals six, since this will throw an error. However, using constant JavaScript is a little funny when working with arrays and objects. For example, if we define an array called numbers, like this, constant numbers 1, 2, 3, 4, 5, we can never directly redefine numbers as a different array like this, numbers equals…

Contents