JavaScript Data Types Explained
JavaScript Data Types Explained
A beginner-friendly guide to the 8 data types in JavaScript with plain-English explanations and simple examples you can try right now.
If you're just starting out with JavaScript, one of the very first things you need to understand is data types. Every value in JavaScript a number, a word, a true/false answer belongs to a "type." Knowing these types helps you avoid bugs and write cleaner code.
What Is a Data Type?
Think of a data type as a category for a value. Just like in real life you might sort things into "fruits," "vehicles," or "furniture," JavaScript sorts values into types like numbers, text, or true/false values.
JavaScript has 8 data types in total, split into two groups: primitive types (7 simple, single values) and the object type (a more complex, collection-like value).
1String Text
A string is just text. Anything wrapped in quotes (single ' ', double " ", or backticks) is a string.
let name = "Sarah";
let greeting = 'Hello there!';
let sentence = `I am learning JavaScript.`;
"123" is a string, not a number.2Number Numbers
A number covers both whole numbers (integers) and decimals (floats). JavaScript doesn't separate them like some other languages do they're all just "number."
let age = 25;
let price = 19.99;
let temperature = -10;
3BigInt Really Big Numbers
Sometimes regular numbers aren't big enough. That's where BigInt comes in it lets you work with extremely large integers. You create one by adding an n at the end.
let hugeNumber = 1234567890123456789012345n;
You probably won't need this often as a beginner, but it's good to know it exists.
4Boolean True or False
A boolean has only two possible values: true or false. It's used for yes/no, on/off type decisions.
let isLoggedIn = true;
let hasFinished = false;
if (isLoggedIn) {
console.log("Welcome back!");
}
5Undefined Nothing Assigned Yet
A variable is undefined when it has been created but hasn't been given a value yet.
let city;
console.log(city); // undefined
Think of it like an empty box with a label on it, but nothing inside.
6Null Intentionally Empty
Null looks similar to undefined, but there's a key difference: null means "this is empty on purpose."
let selectedItem = null; // nothing is selected, and that's intentional
undefined = "nobody set this yet" · null = "someone deliberately set this to empty"7Symbol — Unique Values
A Symbol creates a totally unique value, even if two symbols look the same. This is mostly used in advanced code to avoid naming conflicts, so as a beginner you won't use it much.
let id1 = Symbol("id");
let id2 = Symbol("id");
console.log(id1 === id2); // false, they are unique
8Object — Collections of Data
An object is the odd one out it's not primitive. Objects let you group related data together using key-value pairs.
let person = {
name: "Sarah",
age: 25,
isStudent: true
};
Arrays and functions are actually special kinds of objects too!
let colors = ["red", "green", "blue"]; // an array (a type of object)
Quick Way to Check a Type
JavaScript gives you a handy operator called typeof to check what type something is:
console.log(typeof "Hello"); // "string"
console.log(typeof 42); // "number"
console.log(typeof true); // "boolean"
console.log(typeof undefined); // "undefined"
console.log(typeof null); // "object" (a famous JS quirk!)
console.log(typeof { a: 1 }); // "object"
typeof null returns "object",Even though null is not actually an object, JavaScript returns "object". This is a long-standing bug from the early days of JavaScript. It has never been fixed because changing it would break millions of existing websites and applications that rely on this behavior.Remember: typeof null returns "object" it's a special exception in JavaScript, so it's best to memorize it.
Summary Table
| Type | Example | Description |
|---|---|---|
| String | "hello" | Text |
| Number | 42, 3.14 | Whole numbers and decimals |
| BigInt | 123n | Very large integers |
| Boolean | true, false | Yes/no values |
| Undefined | let x; | Declared but no value |
| Null | let x = null; | Intentionally empty |
| Symbol | Symbol("id") | Unique identifier |
| Object | { name: "Sarah" } | Collection of data |
Final Thoughts
Understanding data types is one of the best foundations you can build as a new JavaScript developer. Once you're comfortable telling strings, numbers, booleans, and objects apart, a huge chunk of confusing beginner errors start to make sense.
The best way to really lock this in? Open your browser console right now and try typing some of the examples above with typeof in front of them. Seeing the results yourself sticks a lot better than just reading about it.

Comments
Post a Comment