Properties of Numbers in Dart
What Are Properties?
In programming, just like in our life, things have their properties. It applies to all things. The properties of cars include brand, maximum speed, engine capacity, etc. The book properties include the author, genre, and number of pages.
Numbers, strings, booleans, and many other types in Dart have properties that make programming more flexible and expressive.
The isEven property is one of the most common for numbers. It returns a boolean value that indicates whether a number is even. If the number is even, the property returns true; if it's odd, it returns false.
main.dart
1234void main() { int number = 2; print(number.isEven); // `true` }
It is especially useful when a variable stores the result of a mathematical expression, as properties help you understand that result more clearly.
main.dart
1234void main() { int result = 2 * -3 * -3 + 13 + 31 * -3 * 31; print(result.isEven); // `true` or `false` }
Another useful property is isNegative. It returns true if the number is negative, and false if the number is positive or equal to zero.
main.dart
1234void main() { int number = 4; print(number.isNegative); // `false` }
All the properties listed above belong to the int type. These properties are not available in other data types (even in double, although it also represents numbers).
Each data type in Dart has its own set of unique properties, and there can be hundreds of them. For now, it's important to understand that different data types serve different purposes and require their own specific approach.
You don't need to remember every property of each data type in Dart. As you learn and practice, you'll naturally become familiar with the most useful ones.
Дякуємо за ваш відгук!
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Awesome!
Completion rate improved to 4.55
Properties of Numbers in Dart
Свайпніть щоб показати меню
What Are Properties?
In programming, just like in our life, things have their properties. It applies to all things. The properties of cars include brand, maximum speed, engine capacity, etc. The book properties include the author, genre, and number of pages.
Numbers, strings, booleans, and many other types in Dart have properties that make programming more flexible and expressive.
The isEven property is one of the most common for numbers. It returns a boolean value that indicates whether a number is even. If the number is even, the property returns true; if it's odd, it returns false.
main.dart
1234void main() { int number = 2; print(number.isEven); // `true` }
It is especially useful when a variable stores the result of a mathematical expression, as properties help you understand that result more clearly.
main.dart
1234void main() { int result = 2 * -3 * -3 + 13 + 31 * -3 * 31; print(result.isEven); // `true` or `false` }
Another useful property is isNegative. It returns true if the number is negative, and false if the number is positive or equal to zero.
main.dart
1234void main() { int number = 4; print(number.isNegative); // `false` }
All the properties listed above belong to the int type. These properties are not available in other data types (even in double, although it also represents numbers).
Each data type in Dart has its own set of unique properties, and there can be hundreds of them. For now, it's important to understand that different data types serve different purposes and require their own specific approach.
You don't need to remember every property of each data type in Dart. As you learn and practice, you'll naturally become familiar with the most useful ones.
Дякуємо за ваш відгук!