DEV Community

Discussion on: Odd or Even?

Collapse
 
jamesrweb profile image
James Robb

This breaks some critical clean code principles, to name a few:

  1. odd_or_even has no block assignment (var, const, let)
  2. The one liner is unnecessary and makes the code harder to read and understand
  3. Duplication of ‘even’ which should be a variable if reused but cannot be in a one line context and doesn’t need to be in a block context as in my version
  4. Using == instead of === for value checks

Don’t get me wrong, this will function fine enough but functioning doesn’t mean its good.

We developers read code far more than we write it and further to that, the industry has more juniors than seniors at any time which makes the readability aspect all the more important. Lastly, proper equality checks and block assignments are essential in languages like JavaScript because global scope pollution can result in overrides and improper equality checks can result in false positives.

Collapse
 
fitsum profile image
fitsum

thanks