The JavaScript type system governs how values behave as numbers, strings, booleans, objects, and other built-in types. JavaScript assigns types to values rather than variables, so one variable can hold values of different types over time. TypeScript builds on this behavior by adding static type checking, making code more predictable before it runs. section 3.3 section 3.3.1 section 7.8
The core rules include:
- Primitive types include number, string, boolean, symbol, null, and undefined; object represents compound values. section 3.3
- JavaScript can coerce values during comparisons and operations, so a number compared with a numeric string may match while addition concatenates them. section 3.2
- The typeof operator reports a value's type, although typeof null returns object because of longstanding language behavior. section 3.3.1
- TypeScript restricts JavaScript's dynamic behavior with annotations, inference, unions, assertions, guards, and special types such as any, unknown, and never. section 7.8
Mixed values can produce surprising results
let hatPrice = 100; let bootsPrice = "100"; if (hatPrice == bootsPrice) { console.log("Prices are the same"); } let totalPrice = hatPrice + bootsPrice; console.log(totalPrice); // 100100 section 3.2
Table 3.1 The JavaScript built-in types (view table figure)
| Name |
Description |
|---|---|
| number |
This type is used to represent numeric values. Unlike other programming languages, JavaScript doesn’t differentiate between integer and floating-point values, both of which can be represented using this type. |
| string |
This type is used to represent text data. |
| boolean |
This type can have true and false values. |
| symbol |
This type is used to represent unique constant values, such as keys in collections. |
| null |
This type can be assigned only the value null and is used to indicate a nonexistent or invalid reference. |
| undefined |
This type is used when a variable has been defined but has not been assigned a value. |
| object |
This type is used to represent compound values, formed from individual properties and values. |
Use the built-in-types table to compare primitive types with object values and review each type's role. section 3.3





