function isOddNumber(num) { return num % 2; }
function isOddNumber(num) { return Boolean(num % 2); }
In my case, I find that:
function isOddNumber(num) { return (num % 2 !== 0); }
Is even more clear than an explicit Boolean conversion. I'm also not a big fan of !!value, as when codebase grows, it becomes hard to skimp through the code.
Great read!
function isOddNumber(num) { return num % 2; }
function isOddNumber(num) { return Boolean(num % 2); }
In my case, I find that:
function isOddNumber(num) { return (num % 2 !== 0); }
Is even more clear than an explicit Boolean conversion. I'm also not a big fan of !!value, as when codebase grows, it becomes hard to skimp through the code.
Cheers! :)
Yes, that definitely works, too! However, I believe you meant
num % 2 !== 0
, though, since we're checking if a number is odd.Either way, I get your point. That's a valid way of thinking about it rather than the explicit and rather bulky
Boolean
call.Ooops, yes, edited my post :)