What are the basic data types in JavaScript?
JavaScript's core types are Boolean (true/false), Number, String (text), and Object/Array (collections) — and a variable's type is decided by its value, not its declaration.
Before JavaScript can work with a piece of data it needs to know what kind of thing it is. The main everyday types are:
| Type | What it holds | Example |
|---|---|---|
| Boolean | A truth value | true, false |
| Number | A number (always floating-point internally) | 42, 3.14, -7 |
| String | Text — a sequence of characters | 'Hello', "World" |
| Object / Array | A collection of several values | {name: 'John'}, [1, 2, 3] |
A defining feature of JavaScript is dynamic typing: you never declare a type, and the same variable can hold different types over time:
let x = 5; // x is a Number
let y = 'hello'; // y is a String
x = 'world'; // perfectly legal — x is now a String
Why type matters: the very same + operator behaves differently depending on the types. 3 + 7 gives 10 (numeric addition), but 'abc' + 'def' gives 'abcdef' (text joined together, called concatenation). Knowing the type of your values is the key to predicting what your code will do.
Go deeper:
MDN: Grammar and types — the full list of JavaScript types (including
null,undefined,BigInt,Symbol) and how dynamic typing works.