Home Videos Exercises MCQ Q&A Quiz E-Store Services Blog Sign in Appointment Payment

JavaScript Data Types

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

Example:
A variable with different data types
let myvariable=1;//numeric value
myvariable='one';//string value
myvariable=true;//boolean value

In the above example, different types of values are assigned to the same variable to demonstrate the loosely typed characteristics of JavaScript. Here, 1 is the number type, 'one' is the string type, and true is the boolean type.

JavaScript includes primitive and non-primitive data types as per the latest ECMAScript 5.1 specification.


Primitive Data types

The primitive data types are the lowest level of the data value in JavaScript. The followings are primitive data types in JavaScript:

Data type Description
String String is a textual content wrapped inside ' ' or " " or ` ` (tick sign).
Number Number is a numeric value.
BigInt BigInt is a numeric value in the arbitrary precision format.
Boolean Boolean is a logical data type that has only two values, true or false.
Null A null value denotes an absense of value.
Undefined undefined is the default value of a variable that has not been assigned any value.

Structural 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.
Date The Date object represents date & time including days, months, years, hours, minutes, seconds, and milliseconds.
Array An array stores multiple values using special syntax.

Here are the key points of Javascript Data types

1. Primitive Data Types

  • Immutable: Once created, their values cannot be changed (a new value creates a new entity in memory).
  • Stored directly in memory (on the stack for faster access).
  • Types include:
    • Number: Handles integers and floating-point numbers, as well as special values like
    • BigInt: Represents large integers beyond limits; created with an suffix.
    • String: Sequence of characters enclosed in quotes (",',or')
    • Boolean: Represents logical values true or false
    • Undefined: A variable declared but not assigned any value.
    • Null: Represents an explicitly empty or non-existent value.
    • Symbol: A unique, immutable value used for object property identifiers.

2. Reference Data Types

  • Mutable: Their content can be changed.
  • Stored as references in memory (heap), with variables pointing to these references.
  • Types include:
    • Object: A collection of key-value pairs.
    • Array: Ordered list of elements.
    • Function: Blocks of reusable code.
    • Date: Represents date and time.
    • Map and WeakMap: Key-value storage with unique keys (WeakMap has weak references).
    • Set and WeakSet: Stores unique values (WeakSet has weak references).