I have a component which is returning NaN whenever the component is empty. According to the coding guidelines of my project I cannot compare anything to NaN.
Is there any workaround to this?
I have a component which is returning NaN whenever the component is empty. According to the coding guidelines of my project I cannot compare anything to NaN.
Is there any workaround to this?
If you need to check for NaN value you can use isNaN
function.
If you need to compare NaN with NaN you can use Object.is(NaN, NaN); // true
Beware Object.is()
wont work in older browsers such as IE 11, you can use polyfill from MDN site: click
You can use isNaN() method, if your parameter is NaN, the method will return true, otherwise will return false. In ES6, Number.isNaN() has the same effect. I don't use "if(object typeof NaN)", you can try it.