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 ?
From 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With