javascript - How do I Convert NaN to a 0? -
when value not entered in 1 of forms, creates later result of nan in javascript. want declare anytime nan show instead show 0. thought adding
<script> = || 0 </script>
to beginning of scripts fine.
is there anyway nan equal 0, no matter situation?
nan
global object cannot override.
reference: https://developer.mozilla.org/en-us/docs/javascript/reference/global_objects/nan
one alternative use isnan
then
a = isnan(a) ? 0 : a;
Comments
Post a Comment