What does "+!!" do in JavaScript? -


this question has answer here:

consider following codes

var value = 0; (var i=0; < arguments.length; i++) {     value += +!!arguments[i]; } 

what +!! here? 1 programming style in javascript?

it's not 1 operator, it's three: + , ! twice.

what apply ! arguments[i], turns truthy values false or falsy values true, , applies ! make false => true , vice-versa, , applies unary + convert result number (true => 1, false => 0).

a falsy value value coerces false. falsy values 0, "", nan, null, undefined, , of course, false. truthy value other value.

so net result add count of truthy values in arguments value.

is 1 programming style in javascript?

using !! turn truthy true , falsy false normal practice. using unary + convert number normal practice.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -