JavaScript Interview Question #3

What are the primitive data types in JavaScript?

JavaScript Fundamentals, Types, Scope & Functions Junior Beginner

Quick Interview Answer

JavaScript has seven primitive data types: string, number, bigint, boolean, undefined, symbol, and null. Primitive values are not objects and are immutable, meaning the primitive value itself cannot be changed in place.

Detailed Explanation

JavaScript has seven primitive data types: string, number, bigint, boolean, undefined, symbol, and null. Primitive values are not objects and are immutable, meaning the primitive value itself cannot be changed in place.

The typeof operator can identify most primitive types, but null is a historical exception: typeof null returns "object". This behavior is retained for backward compatibility.

Code Example

const name = "Asif";          // string
const age = 30;               // number
const big = 9007199254740993n; // bigint
const active = true;          // boolean
let value;                    // undefined
const id = Symbol("id");      // symbol
const selected = null;        // null

console.log(typeof name);     // "string"
console.log(typeof selected); // "object" (historical behavior)