Loading
Datatypes in JS -tutorial
JavaScript is a dynamically typed language, which means you do not need to declare the type of a variable when you create it.
Instead, the type is determined automatically based on the value you assign.



Example:

var a = 30;       // Number (primitive)
var b = "Rahul";  // String (primitive)



Types of Data Types in JavaScript

JavaScript data types are divided into two main categories

  • Primitive Data Types
  • Non-Primitive Data Types (Reference Types)



Primitive Data Types

Primitive data types are the most basic data types in JavaScript. They store single values and are immutable (cannot be changed).



There are 5 main primitive data types

Uploaded Image



  • Number - e.g., var x = 10;
  • String - e.g., var name = "Quipoin";
  • Boolean - e.g., var isOpen = true;
  • Undefined - e.g., var y; (declared but not assigned, value is undefined)
  • Null - e.g., var z = null; (explicitly assigned “no value”)

(In modern JavaScript, sometimes Symbol and BigInt are also included as primitive types, but these are advanced.)



Non-Primitive Data Types

Non-primitive data types, also called reference types, can hold collections of values or more complex data.


Example:


Object

var student = { name: "Rahul", age: 20 };


Array

var numbers = [1, 2, 3, 4, 5];


Function

function greet() { alert("Welcome to Quipoin!"); }


These types can store multiple values and are mutable, meaning their content can be changed.



Key Point

  • JavaScript is dynamically typed - you do not need to specify data types explicitly.
  • Primitive types hold single values and are immutable.
  • Non-primitive types (objects, arrays, functions) can store multiple values and are mutable.