Scalar Types

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

CJavaScriptNote
bool (stdbool.h)boolean
charstringSee note 1.
char / signed charnumberSee note 2.
short intnumber
int / signed intnumber
long long intnumber/bigint
unsigned long long intnumber/bigint
LONG_LONG_MAX (limits.h)Number.MAX_SAFE_INTEGER
unsigned charnumber
unsigned short intnumber
unsigned intnumber
unsigned long long intnumber/bigint
unsigned long long intnumber/bigint
LONG_LONG_MAX (limits.h)Number.MAX_SAFE_INTEGER
floatnumber/bigdecimal
doublenumber/bigdecimal
number
nullnull
undefined
See note 3.

Notes:

  1. char in C and string in JavaScript have different definitions. In C, a char is 1 bytes wide, 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 C 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: