Data types in JS
JavaScript has 8 basic data types. They are split into primitive and reference (object) types.
1. Primitive types (7 total)
A primitive is a value that is not an object and has no methods. They are stored by value, not by reference.
Number
Numbers - both integers and floating-point.
let a = 42;
let b = 3.14;Notes:
- Special values exist:
Infinity,-Infinity,NaN(Not-a-Number). - All numbers in JS are 64-bit floating-point numbers (IEEE 754).
BigInt
Used for very large integers that exceed the limits of Number.
let big = 123456789012345678901234567890n;Adds the
nsuffix. Lets you work precisely with integers of any length.
String
Text strings in quotes: 'single', "double", or template quotes.
let name = "Tim";
let message = `Hello, ${name}!`;Strings are immutable - a new string is created on any change.
Boolean
Logical values - true or false.
let isAdmin = true;
let isLoggedIn = false;Used in conditions, checks, and logical expressions.
Null
A special value denoting "nothing" or "empty".
let user = null;Its type is object (a historical mistake in JavaScript that stuck).
Undefined
A variable declared but with no assigned value.
let x;
console.log(x); // undefinedAssigned automatically when no value is set.
Symbol
A unique, immutable value often used as an object key.
let id = Symbol('id');
let obj = { [id]: 123 };Every Symbol is unique, even with the same description.
2. Reference type
Object
Stores collections of data and functions. Passed by reference, not by value.
let user = { name: "Tim", age: 25 };
let arr = [1, 2, 3];
let func = function() {};Object subtypes:
Object- the base type.Array- an array.Function- a function.Date,RegExp,Map,Set, and so on.
| Data type | Example | Description |
|---|---|---|
| Number | 42, 3.14, NaN | Numbers |
| BigInt | 123n | Large integers |
| String | 'Hello', Hi ${name} | Strings |
| Boolean | true, false | Logical type |
| Null | null | Absence of value |
| Undefined | undefined | Not defined |
| Symbol | Symbol('id') | Unique identifier |
| Object | {}, [], function(){} | Collections and structures |
Short Answer
Interview readyA concise answer to help you respond confidently on this topic during an interview.