Dart num isNaN
Syntax & Examples


num.isNaN property

The `isNaN` property in Dart checks if a number is NaN (Not-a-Number).


Syntax of num.isNaN

The syntax of num.isNaN property is:

 bool isNaN 

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

Return Type

num.isNaN returns value of type bool.



✐ Examples

1 Checking NaN property of NaN and a number

In this example,

  1. We define two variables, number1 and number2, with values double.nan and 5 respectively.
  2. We check their NaN property using the isNaN property and store the results in result1 and result2.
  3. We print the results to standard output.

Dart Program

void main() {
  num number1 = double.nan;
  num number2 = 5;
  bool result1 = number1.isNaN;
  bool result2 = number2.isNaN;
  print('Is $number1 NaN? $result1');
  print('Is $number2 NaN? $result2');
}

Output

Is NaN NaN? true
Is 5 NaN? false

2 Checking NaN property of a number

In this example,

  1. We create a variable number with the value 10.
  2. We use the isNaN property to check its NaN property and store the result in result.
  3. We print the result to standard output.

Dart Program

void main() {
  num number = 10;
  bool result = number.isNaN;
  print('Is $number NaN? $result');
}

Output

Is 10 NaN? false

Summary

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