When a value is not entered in one of my forms, it creates a later result of NaN in the javascript. I just want to declare anytime NaN would show that it would instead show 0. I thought that by simply adding
<script>
a = a || 0
</script>
to the beginning of my scripts that it would be fine.
Is there anyway to say that NaN will just always equal 0, no matter what the situation?
NaN
is a global object that you cannot override.
Reference: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/NaN
One alternative is to use isNaN
then
a = isNaN(a) ? 0 : a;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With