Why JS returns NaN in: + 'any_string'
?
Please check the screenshot:
Why JS returns NaN in: + 'any_string'
?
Please check the screenshot:
Using the unary plus operator you can convert something into a number. By doing +'some_string'
you convert the string to a number, but since some_string
is not a valid number you get NaN
Not a Number.
The "+" tries to convert the string to an integer. See docs here
As it has failed to convert it to a number, the output is NaN : Not A Number
console.log(+"3");
console.log(+"randomString");