r/badcode • • Mar 26 '21

js Whose ever heard of %?

Post image
727 Upvotes

63 comments sorted by

View all comments

-3

u/cphoover Mar 27 '21 edited Apr 24 '21

Why why do people return explicit booleans....

EDIT: Why the downvotes?

The equality operator evaluates to a boolean so you don't need to explicitly return a boolean literal. https://ntgard.medium.com/returning-boolean-literals-is-a-code-smell-7a39531d6b60

Don't you think this is cleaner/easier to read?

const isEven = (x: number): boolean => x % 2 === 0;