What are Primitive Data Types in JavaScript?

Learn about primitive data types in JavaScript

In JavaScript, a primitive is a data type that is not an Object. There are seven primitive data types in JavaScript:

  1. string;
  2. number;
  3. bigint;
  4. boolean;
  5. symbol;
  6. undefined;
  7. null.

Please note that for legacy reasons, typeof null gives you 'object' (as opposed to 'null'). null is actually a primitive type.

In JavaScript, a primitive value is:

  • Immutable;
  • Passed by value;
  • Compared by value;
  • Copied by value.

This is in contrast to an object (which is mutable, and is passed, copied and compared by reference).

In JavaScript, all primitive data types have their object equivalents (except null and undefined) that wrap around the primitive values:

  • String for the string primitive;
  • Number for the number primitive;
  • BigInt for the bigint primitive;
  • Boolean for the boolean primitive;
  • Symbol for the symbol primitive.

These wrapper objects allow you to operate on primitive values by calling object methods on the value. Although, you can explicitly/manually convert a primitive type to its object counterpart, in some cases JavaScript automatically coerces/coverts primitives to its object counterparts. For example, this happens when:

  • You call an object method on a primitive value (e.g. 'foo'.toUpperCase()), or;
  • You pass primitive as the first argument to Function.prototype.call() or Function.prototype.apply() in non-strict mode

In such cases, the wrapper object is thrown away once the operation is complete.

One way to manually convert a primitive to its object equivalent would be to do the following:

String('foobar');
Number(123);
// ...

In case you want to get the primitive value from the wrapper object, you can do so by using the valueOf() method.


Hope you found this post useful. It was published . Please show your love and support by sharing this post.