From the course: Learning Functional Programming with JavaScript ES6+

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Immutability

Immutability - JavaScript Tutorial

From the course: Learning Functional Programming with JavaScript ES6+

Start my 1-month free trial

Immutability

- [Instructor] The first major concept of functional programming is immutability, and it's a concept that may surprise a lot of people at first. Most programmers learned early on that you could assign a value to a variable. For example, we can define a variable called x and store the value five in it. And then, later on in the program, we can change the value of that variable to some completely different number. And later on, we can change this value again, and so on. However, in functional programming, this is not allowed. When we say that x is equal to five, we mean that, for the rest of the program, x will only ever be five. There's no way we can change it. In short, immutability means that most of the values in a program are constant, which, in JavaScript, means using the const keyword instead of the var or let keywords. Another way to think about it is this. In object-oriented and procedural programming, we treat variables as buckets that we can put values into. We call this…

Contents