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

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -