Values in Dart

Dart has various value types including strings, integers, floats, booleans, etc. Here are a few basic examples.

void main() {
  // Strings, which can be added together with +.
  print('dart' + 'lang');

  // Integers and floats.
  print('1+1 = ${1 + 1}');
  print('7.0/3.0 = ${7.0 / 3.0}');

  // Booleans, with boolean operators as you'd expect.
  print(true && false);
  print(true || false);
  print(!true);
}

To run this Dart program, save it as values.dart and use the dart command:

$ dart values.dart
dartlang
1+1 = 2
7.0/3.0 = 2.3333333333333335
false
true
false

In this Dart example, we demonstrate:

  1. String concatenation using the + operator.
  2. Simple arithmetic operations with integers and floating-point numbers.
  3. Boolean operations including AND (&&), OR (||), and NOT (!).

Dart uses string interpolation with ${} to embed expressions inside string literals, which is a convenient feature for formatting output.

Note that Dart, like many modern languages, supports type inference. In this example, we don’t explicitly declare variable types, allowing Dart to infer them based on the assigned values.