Skip to content

Integers

Boa supports the following integer types:

TypeSize (in bytes)Signed ?Minimum valueMaximum value
u81No0255
u162No065535
u324No04294967295
u648No018446744073709551615
i81Yes-128127
i162Yes-3276832767
i324Yes-21474836482147483647
i648Yes-92233720368547758089223372036854775807

Integer literals and type inference

When creating a variable storing an integer without any type annotation, Boa will, in the following order:

  • Assume it is a i32 if the value fits inside a i32
  • Assume it is a i64 if the value fits inside a i64
  • Assume it is a u64 if the value fits inside a u64
  • Raise a compilation error.

The following example illustrates this behavior:

boa
let a = 12 // 12 fits into an i32, so a is an i32
let b = 2147483648 // b is too big for an i32 but fits in an i64 so it is an i64
let c = 9223372036854775808 // c is too big for an i64 but fits in an u64 so it is an u64
let d = 18446744073709551616 // d is too big for an u64 so a compilation error is raised

If the type of the variable is specified and the value does not fit inside it, a compilation error is directly raised:

boa
let a: u8 = 256 // compilation error because 256 is too big to fit in an u8