The `isNegative` property in Dart returns true if the number is negative; otherwise, false.
The syntax of int.isNegative property is:
bool isNegative
This isNegative property of int true if the number is negative; otherwise, false.
int.isNegative returns value of type bool
.
In this example,
negativeNum
with the value -5.isNegative
property to check if it is negative.void main() {
num negativeNum = -5;
bool isNegative1 = negativeNum.isNegative;
print('$negativeNum is negative? $isNegative1');
}
-5 is negative? true
In this example,
positiveNum
with the value 8.isNegative
property to check if it is negative.void main() {
num positiveNum = 8;
bool isNegative2 = positiveNum.isNegative;
print('$positiveNum is negative? $isNegative2');
}
8 is negative? false
In this example,
zero
with the value 0.isNegative
property to check if it is negative.void main() {
num zero = 0;
bool isNegative3 = zero.isNegative;
print('$zero is negative? $isNegative3');
}
0 is negative? false
In this Dart tutorial, we learned about isNegative property of int: the syntax and few working examples with output and detailed explanation for each example.