D Dev Notebook

JavaScript Data Types

Primitive Data Types and Non Primitive Data Types

Data types in JavaScript define the type of data that a variable can store.

JavaScript has several built-in data types, which can be categorized into two main groups: Primitive Types and Non primitive (Reference Types) (Objects).

dev notebook

Primitive Data Types:

These data types represent a single value. They are immutable (cannot be changed) and are stored by value.

These data types represent a single value. They are immutable (cannot be changed) and are stored by value.

  1. String: Represents a sequence of characters enclosed in quotes (' ', " ", or ``).
let myName = "Digital Hero";
  1. Number: Represents both integer and floating-point numbers.
let age = 25; 
let price = 9.99;
  1. Boolean: Represents true or false.
let isStudent = true;
  1. Undefined: A variable that has been declared but not yet assigned a value.
let job; 	// job is undefined
  1. Null: Represents an intentional absence of any value.
let car = null;
  1. Symbol (ES6): A unique and immutable value, typically used as object property keys.
let symbol1 = Symbol('description');

Non Primitive Data Types:

Non-primitive data types are also known as reference types. These types are not directly stored by value but by reference.

  1. Object: Objects are collections of key-value pairs.
let myDetail = { name: "Mohit", age: 25 };
  1. Array: Array used to store ordered lists of values.
let myArr = [1, 2, 3, 4];
  1. Function: Functions can be assigned to variables, passed as arguments, and returned from other functions.
function hello() { return "Hello, World!"; }

On this page