This course has been updated! We now recommend you take the JavaScript: The Recent Parts course.

Check out a free preview of the full ES6: The Right Parts course:
The "Exercise 1 Solution" Lesson is part of the full, ES6: The Right Parts course featured in this preview video. Here's what you'd learn in this lesson:

Kyle walks through the solution to exercise 1. The solution is located in the file ex1-fixed.js.

Get Unlimited Access Now

Transcript from the "Exercise 1 Solution" Lesson

>> [MUSIC]

>> Kyle Simpson: So, let's talk about exercise one. Here we started off with a var x = 2. We can kinda see in the scope of this program that's sorta being used like a constant. So, that's a place where you could make the argument that it should be a const.

[00:00:19] FN is definitely not gonna be treated as a const in the sense it's not gonna be treated as a constant even though it might be reassigned. We're gonna be adding to it, so I think it would be super confusing to declare FN's as a constant, and then later in the code start adding to the contents of it, Okay.

[00:00:37] You can, but I don't think you should. So, that's why we're gonna go ahead and declare fn is a var because we're telling someone, hey this thing is gonna be reused and I use a var instead of a let again because FN's is gonna be used across multiple scopes, all right.

[00:00:50] Now in the previous example I had an iffy in the only purpose of this iffy was so that I could make another var x which was sort of my constant in terms of How high up to go. And there would be a collision there if there wasn't a scope.

[00:01:04] Well, I can do that with a block which I'm doing here. Lines four through ten. And again, I can use const here because x is actually sort of being used as a constant in that sense to tell us what does Run the loop up to. I'm going to do a for with a let keyword because I know I've got closure involved and I'm going to want to close over an individual I for each oop.

[00:01:25] I'm going to add these functions if into the FNs array and just simply close over that I variable.
>> Kyle Simpson: And that preserves my test case. I end up getting true. Questions about exercise one? Yes.
>> Speaker 2: A question from before but, in a more broad sense. Just another question about why ES linked is starting to throw errors for var?

>> Kyle Simpson: [CROSSTALK] There's a crowd of people that are under the impression that light is the new var and that var is a code smell. So, now they have default lending rules that tell you don't use a var under any circumstances. I just think that's a bunch of nonsense but there are some people that believe that.