Hacker News new | past | comments | ask | show | jobs | submit login

The "joke" is that you can determime whether a number is odd or even with a modulo in half the code and a fraction of the storage space of a library. There is no use case for it because it's a built-in feature of the language, and in the age of inane web bloat, supply chain attacks and Javascript cargo-culting, I think laughing at stuff like this is perfectly warranted.



> you can determime whether a number is odd or even with a modulo

Or you could check the lowest bit. Better to abstract away from that implementation decision. ;)


That too, but I get the feeling those kinds of operations aren't in Javascript's standard library...


`my_number & 1 == 0` works.


JavaScript does have bitwise operators. Something I was surprised by was that numbers are stored as 64 bit while all of the bitwise operators operate on 32 but numbers. This means that every operation results in a number conversion first.


Not just 64 bit. 64 bit floating point. You can't just get the "low bit". You need to take the exponent into account to figure out which bit of the mantissa to grab. It's intrinsically more computationally difficult than is-odd on a real integer.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: