articles
My friend Nicholas Zakas made an interesting observation on Mastodon this week: the Array.prototype.every()
method always returns true
for an empty array.
let arr = []; // Returns true arr.every(function (item) { return false; }); // Also returns true arr.every(function (item) { return true; });
Axel Rauschmayer provided an interesting explanation…
.every()
implements universal quantification ("for all", ∀). And that operator is always true for empty sets…That is also how we understand [for all] intuitively if we use it in natural language: "All humans that live on Venus have blue skin" is true (because no humans live on Venus).
The Vanilla JS Academy is a project-based online JavaScript workshop for beginners. Click here to learn more.
Cheers,
Chris
Want to share this with others or read it later? View it in a browser.
0 Komentar untuk "[Go Make Things] The Array.prototype.every() method always returns true for an empty array"