DEV Community

Discussion on: I work hard in order to avoid work - My view on refactoring

Collapse
 
nombrekeff profile image
Keff

There's nothing wrong in using it, and yeah I agree in part. But you can't expect developers to be 100% concentrated and careful 100% of the time, we're humans and as humans we might have a bad day, we might have not slept well, etc... A new developer might not yet know how the unary operator work, it's not intuitive at all. You already need a good knowledge of the language.

So if I have the choice I will use other options before the unary operator to convert strings to numbers. This way we reduce the possibilities of a miss. And I usually prefer to make my code literal, ie using Number('1') or parseInt('1') instead of +1. It might be a personal preference, but I really think it can be beneficial to not use it if it can be omitted.