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,
- We define two variables,
number1
andnumber2
, with valuesdouble.nan
and 5 respectively. - We check their NaN property using the
isNaN
property and store the results inresult1
andresult2
. - 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,
- We create a variable
number
with the value 10. - We use the
isNaN
property to check its NaN property and store the result inresult
. - 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.