What does Nan mean in Javascript?

Asked

Viewed 4,312 times

36

When we have an error in the sum of a number with Javascript, it is returned NaN.

Example:

parseInt('a') + 3; //NaN

What does it mean NaN?

5 answers

33


Global ownership NaN is a special value that means Not-A-Number (is not a number).

Source: MDN

Say the description there:

NaN is a property of the global object, not rewritable, not configurable and not enumerable.

In modern browsers, the NaN is a read-only and not configurable property. Even when this is not the case, avoid overwriting it.

The use of NaN. It is returned when a mathematical operation fails (for example: Math.sqrt(-1)), or when a function tries to turn a string into an integer for example parseInt("blabla").

NaN validate false when converted into Boolean and can be used isNaN() to check if a value is NaN.

17

Definition and Use The Nan property represents a value "Not-a-Number". This property indicates that a value is not a legal number.

The Nan property is the same as the Number.Nan property

It is also returned Nan when a mathematical operation does not return an understandable value or when you try to sum some numbers, but in some of your fields there is no value, and there is no Try Cath to treat the exception, thus, he cannot complete the mathematical operation.

16

Nan stands for Not-A-Number.

It means something is not a valid number.

In this case, you are trying to parse from 'a' to INT, but 'a' is not a number, so the Nan error is generated (Not-a-number).

more information: http://www.w3schools.com/jsref/jsref_number_nan.asp

14

The estate NaN represents "Not -to- NUmber".

This property indicates that a value is not a legal number.

source - w3schools

3

  • This has been answered before, including the link is the same as the @Sergio reply, but is translated.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.