Dart int isNegative
Syntax & Examples

int.isNegative property

The `isNegative` property in Dart returns true if the number is negative; otherwise, false.


Syntax of int.isNegative

The syntax of int.isNegative property is:

 bool isNegative 

This isNegative property of int true if the number is negative; otherwise, false.

Return Type

int.isNegative returns value of type bool.



✐ Examples

1 Check a negative number

In this example,

  1. We create a num variable negativeNum with the value -5.
  2. We access its isNegative property to check if it is negative.
  3. We then print the result to standard output.

Dart Program

void main() {
  num negativeNum = -5;
  bool isNegative1 = negativeNum.isNegative;
  print('$negativeNum is negative? $isNegative1');
}

Output

-5 is negative? true

2 Check a positive number

In this example,

  1. We create a num variable positiveNum with the value 8.
  2. We access its isNegative property to check if it is negative.
  3. We then print the result to standard output.

Dart Program

void main() {
  num positiveNum = 8;
  bool isNegative2 = positiveNum.isNegative;
  print('$positiveNum is negative? $isNegative2');
}

Output

8 is negative? false

3 Check zero

In this example,

  1. We create a num variable zero with the value 0.
  2. We access its isNegative property to check if it is negative.
  3. We then print the result to standard output.

Dart Program

void main() {
  num zero = 0;
  bool isNegative3 = zero.isNegative;
  print('$zero is negative? $isNegative3');
}

Output

0 is negative? false

Summary

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.