var fn = function even (n) {
if (n === 0) {
return true
}
else return !even(n - 1)
}
fn(5)//=> false
fn(2) //=> true
Why does this function work the way it does? When I step through it when the argument is 5 it seems to call itself until n is zero which would return true but it returns false.
!!!!!falseistrue. In short: The result is negated when!is applied odd timesfunction isEven(num) { return num % 2 === 0; }var isEven = n=> (n&1)===0orvar isEven = n => !(n&1); but this is OT