Scalar Types

The following table lists the primitive types in Rust and their equivalent in JavaScript:

RustJavaScriptNote
boolboolean
charstringSee note 1.
i8numberSee note 2.
i16number
i32number
i64number/bigint
i128number/bigint
isizeNumber.MAX_SAFE_INTEGER
u8number
u16number
u32number
u64number/bigint
u128number/bigint
usizeNumber.MAX_SAFE_INTEGER
f32number
f64number
number
()null
undefined
objectSee note 3.

Notes:

  1. char in Rust and string in JavaScript have different definitions. In Rust, a char is 4 bytes wide that is a Unicode scalar value, but in JavaScript, a character is 2 bytes wide and stores the character using the UTF-16 encoding. There is no char type equivalent in JavaScript, only string. For more information, see the Rust char documentation.
  2. There are only three number data type in JavaScript, number, which is essentially a floating point number. And the bigint type for storing numbers that exceed the range -(253 - 1) (Number.MIN_SAFE_INTEGER) to 253 - 1 (Number.MAX_SAFE_INTEGER). and the bigdecimal type for storing high-precision decimals.
  3. For historical reasons, JavaScript has two empty data types: null and undefined. undefined denotes a value that was never created, and null denotes a value that was created but intentionally left empty. See also: