javascript - Why does isNaN(" ") equal false -


I have a quick question (I hope!). In JS, why do isNaN ("") wrong, but evaluate to isNa ("x") correct?

I am performing numeric actions on the text input field, and checking that the field is empty, "", or NaN, when a person finds a handful of spaces in the area, then my The validation fails in all three, and I am confused about why this isNAN has been investigated.

Thank you!

Javascript interprets an empty string as a 0, which then fails in the ISNAN test is. You can use parseInt on the string which will not convert an empty string to 0. The result should be unsuccessful. NAN


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -