Lodash project .inRange() method

I have read through most of the questions asked relating to inRange() method in the forum and realized that no one is asking about the “let” and “const” and “;”.

Why is the help video showing the use of “var” when declaring “temp”? I thought we are now using let and const. is this video out of date?

also, the help video shows the absence of “let” and “const”. how come? please explain.
for example, the video shows this:

inRange(number, start, end){
if (!end){
end = start
start = 0
};
if (start > end){
var temp = end
end = start
start = temp
};

My third question is why this code works without let, const, or var when declaring end or start? And why is there no semicolon after each statement line? Thanks.

Hey @script0131595176,

Those are some valid questions :wink: Ill try to explain.

Why is the help video showing the use of “var” when declaring “temp”? I thought we are now using let and const. is this video out of date?

I wouldn’t say this video is out of date. This is more the case of the programmer explaining the course is not yet familiar with Javascript ES6 or is the victim of “old habits don’t die”. I wouldn’t pay much attention to this, the fact you question this tells me you know very much what it should be in ES6 :wink: . I’ll notfiy the codecademy staff of this @alyssavigil.

My third question is why this code works without let, const, or var when declaring end or start? And why is there no semicolon after each statement line? Thanks.

end and start are no declarations, merely reassignments of already existing variables since they were presented as input parameters in the function. Therefore you don’t have to use let, const or var for that matter.

The semicolons not being used is a bad habit by the instructor, although some people prefer to not use them at all. A semi-colon is not always necessary (in this case because the the code is well encapsulated within the {}, however to me it is not good to not use them here.

@alyssavigil your thoughts on this? What do we want to teach our students?

Link to assignment: https://www.codecademy.com/paths/web-development/tracks/web-dev-js-arrays-loops-objects/modules/pjs-javascript-capstone/projects/lodash

Well this is interesting. The keywords here is: “no declarations, merely reassignments”. I have to keep this in mind. Thanks for explaining this. I’ve gone this far in the track and I thought I missed something.

I got so used to using semi-colons that this looked strange to me and threw me off. A big thanks.

1 Like