Using “Boolean” as the argument to .filter() in JavaScript

Boolean is not a keyword, it is a function, and functions are just objects, that you can pass around. It is the same as:

return arrayOfSheeps.filter(function(x){return Boolean(x)}).length;

Since function(x){return f(x)} === f then you can simplify:

return arrayOfSheeps.filter(Boolean).length;

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)