-2

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?

Shreyash Sharma
  • 310
  • 2
  • 11

2 Answers2

1

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

Aleksa Arsić
  • 524
  • 1
  • 8
  • 16
0

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.

yangchenxi
  • 21
  • 4