What kinds of data exist?
Not everything is the same kind of thing
In real life, a name and an age are different kinds of things. One is words, the other is a number. JavaScript feels exactly the same way. The "kind" of a value is called its data type.
For a beginner, three types cover almost everything.
1. String — text
Any text, always wrapped in quotes.
let city = "Mumbai";
let emoji = "🔥";
Single or double quotes both work — 'Mumbai' and "Mumbai" are the same.
2. Number — well, numbers
No quotes. You can do maths with them.
let price = 99;
let temperature = -5;
let rating = 4.5; // decimals are fine too
3. Boolean — yes or no
This one has only two possible values: true or false. Think of it like a switch — on or off. It is the heart of every decision a program makes.
let isLoggedIn = true;
let hasPaid = false;
How do I check a value's type?
JavaScript gives you a small tool called typeof:
console.log(typeof "Mumbai"); // "string"
console.log(typeof 99); // "number"
console.log(typeof true); // "boolean"
Why should you care about types?
Because mixing them up gives strange results. Watch this closely:
console.log(5 + 5); // 10 (number + number = maths)
console.log("5" + "5"); // "55" (text + text = joined together!)
Same + sign, completely different result — all because of the type. This one confusion is behind a huge number of beginner bugs. Now you know the secret.
Remember: String = text in quotes, Number = maths, Boolean = true or false. The type decides how JavaScript behaves.