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,
- We define a double
numwith a finite value of3.14. - We access the
isNaNproperty to check ifnumis NaN. - 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,
- We define a double
numwith a value of positive infinity. - We access the
isNaNproperty to check ifnumis NaN. - 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,
- We define a double
numwith a value of NaN. - We access the
isNaNproperty to check ifnumis NaN. - 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.