Scalar Types
The following table lists the primitive types in C and their equivalent in JavaScript:
C | JavaScript | Note |
---|---|---|
bool (stdbool.h) | boolean | |
char | string | See note 1. |
char / signed char | number | See note 2. |
short int | number | |
int / signed int | number | |
long long int | number /bigint | |
unsigned long long int | number /bigint | |
LONG_LONG_MAX (limits.h) | Number.MAX_SAFE_INTEGER | |
unsigned char | number | |
unsigned short int | number | |
unsigned int | number | |
unsigned long long int | number /bigint | |
unsigned long long int | number /bigint | |
LONG_LONG_MAX (limits.h) | Number.MAX_SAFE_INTEGER | |
float | number /bigdecimal | |
double | number /bigdecimal | |
number | ||
null | null | |
undefined | ||
See note 3. |
Notes:
char
in C andstring
in JavaScript have different definitions. In C, achar
is 1 bytes wide, 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 Cchar
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: