DEV Community

Mark Tony
Mark Tony

Posted on

Data Types in JavaScript

A data type tells the computer what kind of data a variable stores and what operations can be done with it.

For example:

10 → number
"Hello" → text
true → boolean

In simple words, a data type defines what kind of value a variable can hold.

There are Two types of Data types used in JavaScript:

  1. Primitive Data Type
  2. Non- Primitive Data Type

Primitive Data Type:
It can hold only single value. For example:
let Name= "Tony"

A memory will be created on the key "Name" and the value "Tony" will be stored. The Primitive Data Types are immutable.

If I give another value in the same key "Name" and give the value "Parthipan"

Name="Parthipan"

A new memory will be created and the value "Parthipan" will be stored.

Non- Primitive Data Type
Unlike Primitive,It can Store multiple values. It is called an Object. The object contains the Arrays and Functions.

  let userDetails = {
      name: "Mark Tony",
      email: "tony@gmail.com",
      location: "chennai",
      welcome: function (a,b){
        return a+b;
      },
    };
Enter fullscreen mode Exit fullscreen mode

Various Primitive data types:

  1. String: A string is a sequence of text or characters written inside single quotes (' ') or double quotes (" ").
  2. Number: A number represents both integer and decimal (floating-point) values.
  3. BigInt: BigInt is used to represent very large integers accurately beyond the safe range of the Number type.
  4. Boolean: A Boolean represents a logical value that can be either true or false.
  5. Null: Null represents the intentional absence of a value.
  6. Undefined: Undefined means a variable has been declared but no value has been assigned to it.
  7. Symbol: A Symbol is a unique and immutable primitive value, commonly used to create unique object property keys.

Easy way to remember

  • String → Text
  • Number → Numbers
  • BigInt → Very large integers
  • Boolean → True/False
  • Null → Intentional empty value
  • Undefined → No value assigned
  • Symbol → Unique value

Top comments (0)