Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Properties of Numbers in Dart | Variables and Data Types in Dart
Introduction to Dart

bookProperties 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

main.dart

copy
1234
void 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

main.dart

copy
1234
void 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

main.dart

copy
1234
void 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.

Note
Note

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.

question-icon

Use the isEven property and check if an even number is stored in the num variable.

print();

Click or drag`n`drop items and fill in the blanks

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 3

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Suggested prompts:

Can you give examples of how to use these properties in Dart code?

What are some other common properties for different data types in Dart?

Why aren't these properties available for the double type?

Awesome!

Completion rate improved to 4.55

bookProperties of Numbers in Dart

Sveip for å vise menyen

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

main.dart

copy
1234
void 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

main.dart

copy
1234
void 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

main.dart

copy
1234
void 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.

Note
Note

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.

question-icon

Use the isEven property and check if an even number is stored in the num variable.

print();

Click or drag`n`drop items and fill in the blanks

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 3
some-alt