DEV Community

Divya Divya
Divya Divya

Posted on

What is datatype in js?

Data type is the type of value you store in a variable.It's Datatype categorizes into two type of group.There are Primitive data type and Non-Primitive data type.
Primitive data type: Primitive is a Stores single value , Copied by value and Cannot be changed.

  • Numbers: Numbers used for Integer and Decimal numbers.

For example:

let age=20;
let price=19.97;
Enter fullscreen mode Exit fullscreen mode
  • String:String used for Single quotes or Double quotes.

For example:

let message ="Hello World"
Enter fullscreen mode Exit fullscreen mode
  • Boolean: Boolean is used for True or False.

For example:

let isLogin=true;
Enter fullscreen mode Exit fullscreen mode
  • Undefined: It's used to a variable declared but no value given.

For example:

let a;
console.log(a);
Enter fullscreen mode Exit fullscreen mode
  • Null: Null is used to Empty value.

For example:

let data=null;
Enter fullscreen mode Exit fullscreen mode
  • BigInt: It's a for very large numbers.

For example:

let big=1234567890n;
Enter fullscreen mode Exit fullscreen mode

Non-Primitive data types:It is a Stores multiple values , Copied by reference and Can be changed.

  • Object: Object is a Stores data in key–value pairs.

For example:


  let person = {
  name: "Leela",
  age: 30,
  city: "Chennai"
};

Enter fullscreen mode Exit fullscreen mode
  • Array:Array is used for an ordered list of values.

For example:

let colors=["red","blue","black"];
console.log(colors[1]);
Enter fullscreen mode Exit fullscreen mode
  • Function:Function is a block of code designed to perform a task.

For example:

let add = function(a, b) {
  return a + b;
};

Enter fullscreen mode Exit fullscreen mode

Top comments (0)