Dart double isNaN
Syntax & Examples

double.isNaN property

The `isNaN` property checks if the number is the double Not-a-Number (NaN) value.


Syntax of double.isNaN

The syntax of double.isNaN property is:

 bool isNaN 

This isNaN property of double true if the number is the double Not-a-Number value; otherwise, false.

Return Type

double.isNaN returns value of type bool.



✐ Examples

1 Check if a number is NaN

In this example,

  1. We define a double num with a finite value of 3.14.
  2. We access the isNaN property to check if num is NaN.
  3. We print the result to standard output.

Dart Program

void main() {
  double num = 3.14;
  bool isNumNaN = num.isNaN;
  print('Is 3.14 NaN? $isNumNaN');
}

Output

Is 3.14 NaN? false

2 Check if infinity is NaN

In this example,

  1. We define a double num with a value of positive infinity.
  2. We access the isNaN property to check if num is NaN.
  3. We print the result to standard output.

Dart Program

void main() {
  double num = double.infinity;
  bool isNumNaN = num.isNaN;
  print('Is infinity NaN? $isNumNaN');
}

Output

Is infinity NaN? false

3 Check if NaN is NaN

In this example,

  1. We define a double num with a value of NaN.
  2. We access the isNaN property to check if num is NaN.
  3. We print the result to standard output.

Dart Program

void main() {
  double num = double.nan;
  bool isNumNaN = num.isNaN;
  print('Is NaN NaN? $isNumNaN');
}

Output

Is NaN NaN? true

Summary

In this Dart tutorial, we learned about isNaN property of double: the syntax and few working examples with output and detailed explanation for each example.