If...else statement

Hi Guys!

Is [1] the same as [2]?

[1]

let lengthCheck = storyWords.every((word) => { if (word.length < 10) { return true; } else { return false; } });

[2]

let lengthCheck = storyWords.every((word) => { return word.length < 10 });

Thanks!

https://www.codecademy.com/courses/introduction-to-javascript/projects/mini-linter

Hi,
Yep.
(word.length < 10)
will be equal to either true or false, so 1 is basically,
if (true)
return true
else
return false

So, 2 is basically doing the same job in less code, by returning the result of the condition.

Hope that helps

1 Like

Thanks, @pluginmaybe! All clear :wink: