Check out a free preview of the full Functional JavaScript First Steps course

The "Pure Functions Exercise" Lesson is part of the full, Functional JavaScript First Steps course featured in this preview video. Here's what you'd learn in this lesson:

Students are instructed to decide whether each function is pure or impure.

Preview
Close

Transcript from the "Pure Functions Exercise" Lesson

[00:00:00]
>> Now that we talked a bunch about what is a pure function, what is not a pure function. We're gonna put this into practice. So, we're going to look at some code and we're going to assess which functions are pure and which ones are not, and think about why.

[00:00:14]
So, in the next notebook in this collection, which we can access right here, pure functions exercise. You have your first observable notebook that I'm gonna encourage you to play with. So this is an exercise where you get to look at some code and then decide for each one, whether it's pure or not pure.

[00:00:44]
And when you think you're set on the answer, you can click the reveal answer button. And you will find out, and there's also a little bit of an explanation. So you can think about why. And make sure that that matches up with your understanding of why each function is pure or not.

[00:01:01]
And you will see those answers show up as soon as you hit those buttons. And also this code, what we're looking at here, this is live code. So you can edit it if you want to. But in this case, just to make sure we're all on the same page about which functions we're talking about, and how they behave.

[00:01:22]
We are probably not gonna want to edit any of this code. Just because, right now, we're just gonna make sure check our understanding of purity, and make sure that we're all on the same page about what's pure and what's not pure. So you can go to this exercise, pure functions.

[00:01:38]
And again, if you'd like to make a copy of any of the notebooks that we look at today, you can go to this three dots menu and hit the fork button. And you may need to sign up for an observable account. Again, it's free, uses existing logins that you have.

[00:01:54]
But then you will have one in your own account that you can mess with however you want. But you don't need to do that for this case, you don't need to sign up for anything. You can just hit those buttons and see the updates happen live in your browser.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now