Data Types
(number, string, boolean, null, undefined, symbol)
Definition
A data type tells JavaScript what kind of information a value is.
Why Data Types Matter
Beach Ball Example
A beach ball won’t fit in a shoebox. Some actions only work with certain data types.
Math Class Example
If you want to solve: A + B = C, then A and B should be numbers. let A = 1; let B = “NIKE”;
This doesn’t work like normal math because “NIKE” is text, not a number.
The 6 Main Data Types
Number: Used for numbers (including decimals) let score = 100; let temperature = 98.6;
String: Text in quotes let name = “Andy”; let message = “Welcome to JavaScript!”;
Boolean: Only true or false let isGameOver = false; let isLoggedIn = true;
Null: Intentionally empty let currentPlayer = null;
Undefined: Not assigned yet let result; console.log(result); // undefined
Symbol (Advanced): A unique identifier let id = Symbol(“unique”);
Mini-Quiz
- What data type is “Hello”?
- What’s the difference between null and undefined?