What does "+!!" do in JavaScript? -
this question has answer here:
- +!! operator in if statement 6 answers
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
Post a Comment