Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
Will a zero number return true using IsNaN?

I'm having a little bit of an issue with IsNaN. When the number 'Zero' is passed to it, it fires off as true, rather than false as expected.

I'm parsing a number from a string, converting it to a float using parseFloat:

let val = parseFloat(value.substring(value.indexOf(";")+1, value.lastIndexOf(";")));

then storing 'val' in an array This works perfectly fine and works as expected, however when I later check to make sure it is in fact a number with IsNAN, using this line of code: let DispVal = (isNaN(val) || val== "")? "Value: Loading" : "Value:" + val;

This works perfectly fine, unless the number is zero. If the number is zero it uses it's set to 'Value: Loading'

I had thought this may be due to '0' also being considered false, but the way the documentation for isNaN has me doubting that somewhat

Is there something I'm doing wrong here, or some where our data might be getting mangled

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In js the result of the expression 0 == "" is (surprisingly) true.

This is because "" is being coerced into a number and Number("") is 0

So when val is equal to 0 you get your loading state

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!