Skip to content
Blog

Getting to Know Dart's Core Types: int, double, bool and String

From 64-bit ints to UTF-16 strings, meet Dart's four everyday types: their literals, platform limits, literal inference, and why bool has no truthiness.

Published on • December 3, 2026

AI Assistant

Almost every Dart program begins with four types: int, double, bool and String. They look so familiar that it is tempting to skip them, yet each carries details — platform-dependent integer ranges, IEEE 754 surprises, an entire boolean type with no truthiness, UTF-16 strings — that quietly shape correct code.

Numbers: int and double

Dart has exactly two number flavors. int is an integer of up to 64 bits depending on the platform: on native platforms values run from -263 to 263 - 1, while on the web integers are represented as JavaScript numbers and top out at 253 - 1. double is a 64-bit double-precision floating-point number as specified by the IEEE 754 standard. Both are subtypes of num, the type that carries the shared arithmetic operators.

void main() {
  var x = 1;                 // int
  var hex = 0xDEADBEEF;      // int, written in hexadecimal.
  var y = 1.1;               // double
  var exponent = 1.42e5;     // double: 142000.0
  var grouped = 1_000_000;   // int with digit separators (Dart 3.6+).

  print('$x $hex $y $exponent $grouped');
}

The literal rules are worth memorizing: an integer literal has no decimal point, a number with a decimal point or an exponent is a double, and 0x introduces a hexadecimal integer. Underscores as digit separators — available from language version 3.6 onward — make long literals scannable, grouping however you like: 1_000_000, 0x00_14_22_01_23_45, even 100__000_000__000_000.

Because int is a subtype of num, a variable declared num legitimately holds either kind, and the shared methods such as abs(), ceil(), floor() and clamp() live on num while bitwise operators like >> and & belong to int alone.

void main() {
  const maxNative = 9223372036854775807; // 2^63 - 1 on native platforms.
  const maxWeb = 9007199254740991;       // 2^53 - 1 on the web.

  num value = maxNative;
  value += 2.5; // num holds both int and double.
  print(value);

  print((3 << 1) == 6); // 0011 << 1 == 0110
  print((3 | 4) == 7);  // 0011 | 0100 == 0111
}

If the literal in your head exceeds the web’s 53-bit safe range, the value silently rounds on the web while staying exact on native platforms — one reason to prefer int arithmetic that stays well inside the safe range for code that also ships as JavaScript.

double: precise, until it isn’t

Every double is IEEE 754 binary64, which means most decimal fractions cannot be represented exactly. The classic 0.1 + 0.2 does not equal 0.3, and no amount of int-style reasoning will change that. The type provides the answers you should use instead: isNaN, isInfinite and isFinite, plus careful comparisons.

void main() {
  var sum = 0.1 + 0.2;
  print(sum);              // 0.30000000000000004
  print(sum == 0.3);       // false
  print(sum.isFinite);     // true

  var nan = 0 / 0;
  print(nan.isNaN);        // true
  print(nan == nan);       // false: NaN isn't even equal to itself
}

Never test floats for exact equality when they came from arithmetic; compare with a tolerance, or work in integers of minor units when exactness matters.

bool: only true and false

Dart has exactly two objects of type bool: the compile-time constants true and false. Unlike JavaScript or Python, there is no truthy or falsy — an empty string is not “false,” it is a String, and the type system rejects it outright in a condition. You must ask an explicit question.

void main() {
  var fullName = '';
  var hitPoints = 0;
  String? unicorn;
  var rolled = 0 / 0;

  print(fullName.isEmpty); // true — ask emptiness, not "truthiness".
  print(hitPoints == 0);   // true — compare against zero.
  print(unicorn == null);  // true — null checks are explicit.
  print(rolled.isNaN);     // true — NaN equals nothing at all.
}

This is a feature: if (fullName) does not compile, so the reader never has to guess what “empty means false” means in that language. Booleans in APIs should also be named to read as predicates — isEmpty, hasElements, canClose — per Effective Dart’s design guidelines.

String: a sequence of UTF-16 code units

A Dart String is a sequence of UTF-16 code units, and you can write it with single or double quotes — the two are interchangeable, and choosing the other one is usually the cheapest way to avoid escaping an apostrophe.

void main() {
  var s1 = 'Single quotes work well for string literals.';
  var s2 = "Double quotes work just as well.";
  var s3 = 'It\'s easy to escape the string delimiter.';
  var s4 = "It's even easier to use the other delimiter.";

  print('$s1 / $s2');
  print('$s3 / $s4');
}

Because the unit of storage is the UTF-16 code unit rather than the user-perceived character, length counts code units. A flag emoji built from two astral-plane code points contributes four units, and slicing naively can split a surrogate pair in half.

void main() {
  var hi = 'Hi 🇩🇰';
  print(hi.length);        // 7 UTF-16 code units
  print(hi.substring(0, 3)); // "Hi "

  print('Heart: \u2665');        // 4-digit hex escape.
  print('Laughing: \u{1f606}');  // braces for more than 4 digits.
}

When you need to manipulate user-perceived characters — grapheme clusters such as flag emojis or accented letters — the characters package exposes them properly. Unicode code points inside a string use \uXXXX, or \u{...} when more than four hex digits are needed.

How literals get their types

Literal typing is inference applied to values: the literal’s form decides its type, and an expected type can refine it. 1 is an int, 1.0 is a double, 'hi' is a String, true is a bool — and when the context expects a double, an integer literal is promoted for you.

void main() {
  double z = 1; // Equivalent to double z = 1.0.
  const screenWidth = 640; // Inferred int.

  print(z);
  print(screenWidth);
}

That promotion is why dart-var-inference.md can lean on var so heavily: the literal already carries the type, and the context only narrows it when necessary. When you move values between strings and numbers instead, the conversion toolkit is covered in dart-num-int-double-conversion.md, and building larger strings from these values is the subject of dart-string-interpolation-raw-strings.md.

The four types at a glance

TypeExample literalsKey properties
int42, 0xDEADBEEF, 1_000_00064-bit native, 53-bit web; subtype of num; owns bitwise operators
double3.14, 1.42e5, 1.0IEEE 754 binary64; / always produces one; check isNaN
booltrue, falseOnly two values; no truthiness; conditions require a real predicate
String'hi', "hi", '''multi'''UTF-16 code units; literals are compile-time constants
numany number aboveSealed supertype of int and double; shared +, -, *, %

Takeaways

Dart’s core types are small in number but specific in behavior: int changes range between native and the web, double is honest IEEE 754 arithmetic where exact decimal equality is a trap, bool refuses to pretend anything else is true or false, and String is a UTF-16 sequence where length counts code units rather than characters. Literals decide their own type and adapt to the context they appear in, which is the foundation the rest of Dart’s type inference builds on.

Takeaway: Master int, double, bool and String first — their literal rules and platform quirks explain most “obvious” bugs in everyday Dart code.

References