Array.every() - why is this enough?

Please explain to me why this code is enough?
I mean, nowhere is it determined that value 0 , null, undefined, “”, NaN is false


function truthCheck(collection, pre) {
  // Is everyone being true?
  return collection.every(obj => obj[pre]);
}

truthCheck(
  [
    { user: "Tinky-Winky", sex: "male" },
    { user: "Dipsy", sex: "male" },
    { user: "Laa-Laa", sex: "female" },
    { user: "Po", sex: "female" }
  ],
  "sex"
);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36.

Challenge: Everything Be True

Link to the challenge:

0, null, undefined, "", and NaN are all “falsy” values. When they are evaluated as booleans, they will be treated as false.

Oops … I forgot this information and didn’t find it on Google. Thanks!

:smiley: That’s what we’re here for.

1 Like