79657608

Date: 2025-06-08 07:28:31
Score: 2
Natty:
Report link

Above answers are excellent answers but are over-engineering the problem. Remember that a rule of thumb is to provide a solution to the existed problem not something else because softwares get complicated very fast and you risk side effects ...

So, you want to convert NaN to 0, not "undefined", not empty string, etc. Only NaN.

Why not creating a function doing that ? it's more simpler and clearer :

function convertToZeroIfNaN(number){...}

Reasons:
  • No code block (0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Zied Nasri