I'm confused by this .every()
behavior.
let a = [true, true, true]
a.every(Boolean) // returns true
let b = [true, false, true]
b.every(Boolean) // returns false
typeof false // returns 'boolean'
I can not understand why b.every(Boolean)
returns false
. What do i miss ?
I'm confused by this .every()
behavior.
let a = [true, true, true]
a.every(Boolean) // returns true
let b = [true, false, true]
b.every(Boolean) // returns false
typeof false // returns 'boolean'
I can not understand why b.every(Boolean)
returns false
. What do i miss ?
-
1
b.every(el => typeof el === "boolean")
returnstrue
. – user5734311 Commented Aug 20, 2019 at 0:38 - @ChrisG yeah, i see now. Thanks – Noob Commented Aug 20, 2019 at 0:43
1 Answer
Reset to default 15From MDN:
The every() method tests whether all elements in the array pass the test implemented by the provided function.
The Boolean
callback that you use converts the variable passed to it to a boolean, so Boolean(false)
will return false
, which makes b.every(Boolean)
return false
as well.