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++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -