Every value in a program has a type, which determines what kind of data it is and what you can do with it. A number can be added; text can be joined; a true/false value can be used in a decision.
| Type | Example | Description |
|---|---|---|
| Number | 42, 3.14 | Whole or decimal numbers |
| String | "hello" | Text, wrapped in quotes |
| Boolean | true, false | A yes/no, on/off value |
| Undefined | undefined | A variable that has been declared but has no value yet |
| Null | null | An intentionally empty value |
JavaScript's typeof operator tells you what type a value is — useful while learning, and occasionally in real code too.
console.log(typeof 42); // "number"
console.log(typeof "hello"); // "string"
console.log(typeof true); // "boolean"
console.log(typeof undefined); // "undefined"Numbers and strings that look similar behave very differently: "5" + "5" joins two pieces of text into "55", while 5 + 5 adds two numbers into 10. Mixing up a number and a string that contains digits is one of the most common early bugs.