Data type in javascript, specifies the type of data a variable is going to store or hold, It is important because on the basis of data types, javascript performs operations on data. Javascript data types are dynamic in nature, it means same variable can hold different type of data, It is also a weakly typed language, so, operation on different types does not give error, operating on different data types On different types, Javascript provides 8 different types of data types.

  • Number
  • Undefined
  • Null
  • Bigint
  • String
  • Boolean
  • Symbol
  • Object

Javascript data types are divided majorly into two types.

  1. Primitive data type
  2. Non Primitive data type

Primitive data type

These are also called in-built data types and 7 in numbers

Number
Undefined
Null
Bigint
String
Boolean
Symbol

Non Primitive data type

These are also called derived data type and reference data type. these are derived from in-built(primitive) data types.

Object

Number

In javascript, numbers can be integer or floating numbers. but javascript treats all numbers as floating point numbers. javascript has some predefined numbers like NaN, +0, -0, Infinity and -Infinity.

<script> 
let a = 40;
let b = 5;
let r1 = 0, r2 = 0, r3 = 0, r4 = 0;
r1 = a + b;
document.write(r1);
r2 = a - b;
document.write(r2);
r3 = a * b;
document.write(r1);
r4 = a / b;
document.write(r1);
</script>

Undefined

In javascript, an uninitialized variable value is by default undefined. it means, a variable is declared and not given or assigned a value, For such variables, javascript by default assigns value undefined.

<script> 
let a;
var b;
document.write(a);
document.write(b);
</script>

Null

In javascript, null represents object has no value.

<script> 
let a = null;
</script>

BigInt

BigInt use to represent larger numbers that are no possible with number data type.

<script> 
let a = 121323413432423n;
let b = BigInt(3243232443243243242);
</script>

BigInt numbers can be created by appending n or using BigInt() function.

String

Strings are series of characters, which are enclosed in single or double quote.

<script> 
let name = 'yourshala';
let country = "India";
</script>

Boolean

Boolean data type represent two values only true or false

<script> 
let isValid = true;
let isRaining = false;
</script>

Symbol

It creates a unique symbol or values.

<script> 
let a = Symbol("hello");
</script>

Object

Object is a collection of properties having key-value or name-value pairs.

<script> 
const bike = {company:"Enfield", model:"Hunter", cc:350, color:"black"};
</script>