Dart int isNaN
Syntax & Examples


int.isNaN property

The `isNaN` property in Dart returns true if the number is the double Not-a-Number value; otherwise, it returns false.


Syntax of int.isNaN

The syntax of int.isNaN property is:

 bool isNaN 

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

Return Type

int.isNaN returns value of type bool.



✐ Examples

1 Check if a finite number is NaN

In this example,

  1. We assign the value 3.14 to the double variable num1.
  2. We check if num1 is NaN using the isNaN property.
  3. We print the result to standard output.

Dart Program

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

Output

Is 3.14 NaN? false

2 Check if positive infinity is NaN

In this example,

  1. We assign double.infinity to the double variable num2.
  2. We check if num2 is NaN using the isNaN property.
  3. We print the result to standard output.

Dart Program

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

Output

Is infinity NaN? false

3 Check if NaN is NaN

In this example,

  1. We assign double.nan to the double variable num3.
  2. We check if num3 is NaN using the isNaN property.
  3. We print the result to standard output.

Dart Program

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

Output

Is NaN NaN? true

Summary

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