Basic Syntax and Data Types of the Dart Programming Language


Basic Syntax and Data Types of the Dart Programming Language

What is Dart? Basic Structural Features

The Dart programming language is a modern and powerful language developed by Google, especially for developing mobile, web, and server-side applications. Dart, which supports both static and dynamic typing, stands out with its easy readability and secure structure. Dart, whose popularity increased as it became known as the main language of Flutter, continues its rapid rise in the software world. In this article, you can find detailed information about the basic syntax and data types of the Dart programming language.

Basic Syntax in the Dart Programming Language

The best way to learn the Dart language is to grasp the basic syntax. In Dart, every code block is delimited by { } (curly braces). Semicolon ; is used at the end of lines. Variables can be defined with the var, final, or const keywords. Functions start with void or a return type. Dart, which is case-sensitive, has a readable structure and is in accordance with modern development standards.

Basic Syntax Example in Dart


void main() {
  print('Hello World!');
  int number = 42;
  print('Number: $number');
}

In the example above, the print() function outputs to the screen, while int number = 42; creates an integer variable. The basic syntax of the Dart programming language is thus quite understandable.

Basic Data Types in the Dart Programming Language

The Dart programming language provides different basic data types that can be assigned to variables.

  • int: Integer values (e.g. 10, -3)
  • double: Decimal numbers (e.g. 3.14, -0.5)
  • String: Text expression (e.g. "Hello")
  • bool: Logical (true/false) value
  • List: Ordered collection (array)
  • Map: Key-value pairs
  • var: Variable whose type is determined at runtime
  • dynamic: Variable whose type can completely change at runtime

Example Usage of Dart Data Types


void main() {
  int age = 28;
  double pi = 3.1416;
  String name = 'Ahmet';
  bool active = true;
  List<String> colors = ['Red', 'Blue', 'Green'];
  Map<String, int> stock = {'apple': 5, 'pear': 3};

  print('Name: $name, Age: $age, Active?: $active');
  print('Colors: $colors');
  print('Stock: $stock');
}

In this example, variables were created with basic data types of the Dart language and transferred to the console using the print() function. Explicitly specifying the type of variables in Dart programming language is one of the best practices. Although the var and dynamic keywords provide flexibility, choosing appropriate data types is important for code readability and ease of maintenance.

Conclusion: Dart Basic Syntax and Data Types

With the basic syntax and data types of the Dart programming language, you can make a quick start to modern application development. Mastering the basic structures will provide you with a great advantage, especially in Flutter and modern software projects. Dart's readable, powerful, and type-safe approach is an indispensable option for both small and large projects.