Sitemap
Ryo Osawa

Ryo Osawa

Software Engineer. Live in San Francisco. Coffee addict.

!! (Double-Not Operator)

1 min readOct 1, 2014

--

I’ve been learning some cool Javascript tricks lately. Using two “!” operators to convert a truthy/falsy value into an actual Boolean type is one of my favorites so far. For example, you can use this trick and reduce function to implement every function.

Get Ryo Osawa’s stories in your inbox

Join Medium for free to get updates from this writer.

var every = function(collection, predicate) {
return collection.reduce(function(prev, item) {
return !!prev || predicate(item);
});
};

--

--

Ryo Osawa
Ryo Osawa

Written by Ryo Osawa

Software Engineer. Live in San Francisco. Coffee addict.