What does NaN mean in javascript?

24

When we have an error in adding a number to JavaScript, NaN is returned.

Example:

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

What does NaN mean?

    
asked by anonymous 13.10.2015 / 22:59

5 answers

26
  

The global property NaN is a special value that means Not-A-Number (not a number).

Source: MDN

It says the description there:

NaN is a global, non-rewritable, non-configurable and non-enumerable object property.

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

It is not usual to use NaN . It is returned when a math operation fails (for example, Math.sqrt(-1) ), or when a function tries to transform a string to integer for example parseInt("blabla") .

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

    
13.10.2015 / 23:05
14

Definition and Usage The NaN property represents a "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

NaN is also returned when a math operation does not return an understandable value or when you try to add some numbers, but in any of its fields there is no value, and there is no TryCode to handle the exception, so it can not complete the math operation.

    
13.10.2015 / 23:04
12

NaN stands for Not-A-Number.

It means something is not a valid number.

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

More information: link

    
13.10.2015 / 23:05
10

The

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

source - w3schools

    
13.10.2015 / 23:05
0

The global NaN property is a special value that means Not-A-Number (not a number).

In the example in question, it is one of the situations that the value 'NaN' is returned, in this case the conversion of an alphabet string to a number.

You can use the isNaN () function to check if a, calculation, conversion, value is equal to 'NaN'. See: link

    
08.06.2017 / 13:52