Arrow function placement with .every() method


#1

https://www.codecademy.com/courses/learn-javascript-iterators/lessons/javascript-iterators/exercises/documentation?action=lesson_resume&course_redirect=introduction-to-javascript

Doing this lesson here on iterators and decided to play around with it a bit and refactor it in the way it’s demo’d in the documentation here:

So the following worked fine:

console.log(interestingWords.every(isCorrectLength));

function isCorrectLength(word){
  return word.length > 5;
}

However, I tried the same thing with the arrow function below and I got ReferenceError: isCorrectLength is not defined

console.log(interestingWords.every(isCorrectLength));

const isCorrectLength = word => word.length > 5;

However, if I switch the statements around the other way like it runs fine:

const isCorrectLength = word => word.length > 5;

console.log(interestingWords.every(isCorrectLength));

The function declaration runs fine either way.

Why is this?


#2
console.log(stuff);  // haven't defined stuff yet
stuff = 5;

function statements on the other hand run before everything else


#3

Good to know, thanks.