Arrow function have something called implicit returns.
So if you write an expression as the body of the arrow function, it will automatically return the result.
So for x = ages.some( (a) => a===18)
, the check a === 18
is returned automatically as the result. The same way as if you had written x = ages.some( (a) => { return a === 18; })
.
For the version with brackets, you don't add a return value, so it always returns undefined, even if a equals 18. You'd need to return explicitly for it to work as shown above.
Array.some() function returns true
if at least one element returns true
for the callback. So written without the brackets, you return true for the 3rd array element and false for the others, resulting in true
for variable x
.
In the version with brackets, you always return undefined
since the function does not return anything. Undefined gets cast to false for all the values and hence, the end result is that variable x
is also false.