Is it possible somehow to return 0 instead of NaN when parsing values in JavaScript?
In case of the empty string parseInt returns NaN.
Is it possible to do something like that in JavaScript to check for NaN?
var value = parseInt(tbb) == NaN ? 0 : parseInt(tbb)
Or maybe there is another function or jQuery plugin which may do something similar?
When not used with boolean values, the logical OR
||operator returns the first expressionparseInt(s)if it can be evaluated totrue, otherwise it returns the second expression0. The return value ofparseInt('')isNaN.NaNevaluates tofalse, sonumends up being set to0.