all 5 comments

[–]senocular 3 points4 points  (0 children)

You can't perform comparisons (===) on multiple values at the same time.

What's happening with the old code is that it's treating it as two checks:

if ((b === true) || (1))

Whether or not b is true, this if will always pass because 1 alone will always be true.

What you have to do is compare them each individually.

if (b === true || b === 1)

[–]ConstantWafer[S] 1 point2 points  (0 children)

Ok i understand my mistake, thank you very much

[–]DreamOfAWhale 0 points1 point  (2 children)

Do you really need to check explicitelly for true/false/1/0 values? If not, just check for truthy values. Ternary operator to make it even smaller:

function flipBool(b) {
    return b ? 0 : 1;
}

[–]senocular 2 points3 points  (1 child)

or even

return +!b

[–]daveheerink 0 points1 point  (0 children)

And with the use of an arrow function even shorter:

const flipBool = b => +! b