javascript - Working vs an old project and find code which I don't understand -
i don't understand following code please explain me
sorry might seem weird, gotta understand
reverse = [-1, 1][+!!reverse];
let's reverse = 5
, !5
false
since every number except 0 thruty, if negate again !false
obtain true
, convert our boolean expression either 1 or 0 using +
.
var reverse = 5; reverse = [-1, 1][+!!reverse];
is same as
var reverse = 5; reverse = [-1, 1][1];
to more explicit have been:
var reverse = 5; reverse = [-1, 1][number(boolean(reverse))];
Comments
Post a Comment