Getting Started with Variables, Data Types, and Functions in Dart
This guide covers variables, data types, and functions, helping you build a strong foundation for your Dart coding journey.
Learn the fundamentals of Dart programming language!
Explore real-time examples and start writing efficient and flexible code today!
Introduction:
Dart is a powerful and easy-to-learn programming language developed by Google. In this guide, we'll dive into the basics of Dart, focusing on variables, data types, and functions.
Variables:
Variables are containers that store data in a program. Discover how to declare and use variables in Dart, and how they contribute to building dynamic applications.
Real-Time Example:
void main() {
String message = "Hello, Dart!";
int age = 25;
double price = 9.99;
bool isStudent = true;
print(message); // Output: Hello, Dart!
print("I am $age years old."); // Output: I am 25 years old.
print("The price is \$$price."); // Output: The price is $9.99.
print("Am I a student? $isStudent"); // Output: Am I a student? true
}
..
Data Types:
Data types in Dart define the kind of data a variable can hold. Explore the different data types and how they impact your code.
Real-Time Example:
void main() {
int score = 100;
double percentage = 93.75;
String name = "John Doe";
bool isActive = true;
print("Score: $score"); // Output: Score: 100
print("Percentage: $percentage"); // Output: Percentage: 93.75
print("Name: $name"); // Output: Name: John Doe
print("Active: $isActive"); // Output: Active: true
}
..
Functions:
Functions are blocks of code that perform specific tasks. Learn how to create and use functions to make your code more organized and reusable.
Real-Time Example:
void main() {
String greeting = greetUser("Alice");
print(greeting); // Output: Hello, Alice!
int sum = addNumbers(5, 7);
print("Sum of 5 and 7 is $sum"); // Output: Sum of 5 and 7 is 12
}
String greetUser(String name) {
return "Hello, $name!";
}
int addNumbers(int a, int b) {
return a + b;
}
..
Comments
Post a Comment