Skip to main content

Data Types in JavaScript

There are two types of data in JavaScript

  • Primitive
  • Non-Premitive : these type of data are also called objects

Primitive data types are of

  • String : data is enclosed with in single quote or double quote.
  • Number : can be any number as well as decimal values
  • Bigint : big numbers
  • Boolean : either true or false
  • Undefined : variable may be declared but any value is not assigned to it.
  • Null : Variable is assigned null value. Intentionally data type is absent. typeof null is object.
  • Symbol : It's constructor returns an unique symbol each time.

Note that javascript is a loosely typed language. Data types are allocated dynamically. Unlike other programming languages like C and java no need to decalre the data type.

Extra Notes

  • Different operators like +, -, *,/,%,++,--,~, ! can be used with integers. Details regarding the operators is not scope of this tutorial. It can be discussed in a separate tutorial.

  • NaN ("Not a Number") is the result of an arithmetic operation when it cannot be expressed as a number. It is also the only value in JavaScript that is not equal to itself.
   +'a'; // 'NaN'
// Remember the first letter is an empty space but not in quotes
  • JavaScript strings are immutable. This means that once a string is created, it is not possible to modify it.

  • A BigInt is created by appending n to the end of an integer or by calling the constructor. We can use all operators like +,-,*,**,% with bigints. In strict mode it is not equal to numbers.

    x = 12345n;
typeof x // 'bigint'