Looking for clarification regarding .every()

Here’s a short code

const isBelow = (currentValue) => {
    console.log(`iteration currentValue is ${currentValue}`);
    currentValue < 40;

const array1 = [1, 30, 39, 29, 40, 13];


Based on the assumption that .evey(() is iterating through each of the array’s elements I was expecting it to return each iteration’s current (1, 30, 39, 29) value and when reaching the 40 in the array to return false
but the output I get is

iteration currentVaalue is 1

what do I get wrong?

you do not return this condition currentValue < 40; from the function, therefore the array elements can’t be compared to the condition.
Either you write the arrow function in shorthand syntax like:

const isBelow = (currentValue) =>  currentValue < 40;

or you use the return keyword.

thanks @mirja_t
I’ve followed you suggestino, added the return keyword and i got the expected result.

But I am still not clear why did the initial code returned the console.log of 1 and the value of false?

btw I copied the code for MDN
And in their code they did not put the return

No, they use the shorthand syntax as I also posted it above. ‘return’ is implied when using shorthand syntax.
If you don’t return a value from an arrow function, it returns ‘undefined’ by default. ‘undefined’ is a falsy value, that’s why you get ‘false’.

1 Like

Thank you
I have had another look, this time closer look and realized my mistake

1 Like