0

I'm having trouble with a Windows Scripting Host script.

Here is an example of problem input code:

WScript.Echo(typeof(parseInt('woot')))
WScript.Echo(parseInt('woot'))

The output is:

number
1.#QNAN

Shouldn't 'woot' be evaluating as a string? How can I get around this limitation?

posfan12
  • 2,541
  • 8
  • 35
  • 57

3 Answers3

0

Anything from parseInt is a number, since even NaN is treated a number by JS.Therefore, you'd need to check the type of 'woot' before you parseInt it.

lincb
  • 622
  • 5
  • 20
0

You can check if parseInt return NaN (not a number)

isNaN(parseInt('woot', 10))

typeof return number becouse NaN is number in JavaScript

But remember that isNaN is litle bit broken read more#Examples

adam187
  • 3,193
  • 21
  • 15
0

I found a solution here:

Validate decimal numbers in JavaScript - IsNumeric()

Can a mod please close this request?

Community
  • 1
  • 1
posfan12
  • 2,541
  • 8
  • 35
  • 57