Scalar Types
The following table lists the primitive types in Rust and their equivalent in JavaScript:
Rust | JavaScript | Note |
---|---|---|
bool | boolean | |
char | string | See note 1. |
i8 | number | See note 2. |
i16 | number | |
i32 | number | |
i64 | number /bigint | |
i128 | number /bigint | |
isize | Number.MAX_SAFE_INTEGER | |
u8 | number | |
u16 | number | |
u32 | number | |
u64 | number /bigint | |
u128 | number /bigint | |
usize | Number.MAX_SAFE_INTEGER | |
f32 | number | |
f64 | number | |
number | ||
() | null | |
undefined | ||
object | See note 3. |
Notes:
char
in Rust andstring
in JavaScript have different definitions. In Rust, achar
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 nochar
type equivalent in JavaScript, onlystring
. For more information, see the Rustchar
documentation.- There are only three number data type in JavaScript,
number
, which is essentially a floating point number. And thebigint
type for storing numbers that exceed the range -(253 - 1) (Number.MIN_SAFE_INTEGER
) to 253 - 1 (Number.MAX_SAFE_INTEGER
). and thebigdecimal
type for storing high-precision decimals. - For historical reasons, JavaScript has two empty data types:
null
andundefined
.undefined
denotes a value that was never created, and null denotes a value that was created but intentionally left empty. See also: