JavaScript DataTypes


Javascript Data Types

In JavaScript, you can assign different types of values to a variable e.g. string, number, boolean, etc. JavaScript provides different data types to hold different types of values.

There are two types of data types in JavaScript.

1. Primitive data type

  1. String
  2. Number
  3. Bigint
  4. Boolean
  5. Undefined
  6. Null

2. Non-primitive (reference) data type

  1.  An object
  2. An array
  3.  A date

JavaScript Dynamic type Language

JavaScript is a dynamic type language, means you don't need to specify type of the variable because it is dynamically used by JavaScript engine. You need to use var here to specify the data type. It can hold any type of values such as numbers, strings etc.

Example

var a=30;//holding number
var b="Rahul";//holding string

1. JavaScript primitive data types

The followings are primitive data types in JavaScript.

Data TypeDescription
StringIt represents sequence of characters e.g. "hello"
NumberIt represents numeric values e.g. 100
BigIntIt is a numeric value in the arbitrary precision format. e.g. 453889879865131n, 200n, etc.
BooleanIt represents boolean value either false or true
UndefinedIt represents undefined value
NullIt represents null i.e. no value at all

2. JavaScript Non-primitive data types

The structural data types contain some kind of structure with primitive data.

Data Type Description
Object An object holds multiple values in terms of properties and methods.

Example
let person = { 
                firstName: "Rahul", 
                lastName: "Kumar", 
                age: 30
            }; 
Date The Date object represents date & time including days, months, years, hours, minutes, seconds, and milliseconds.
Example
today = new Date("27 May 2023");
Array An array stores multiple values using special syntax.
Example
let nums = [1, 2, 3, 4];

Prev Next