Practice: Create Variables
Text vs Numbers in Variables
Why this matters: mixing text and numbers is a common beginner pitfall—quotes decide whether JavaScript treats a value as data to display or a quantity to compute.
Variables can store different kinds of data. Two essentials:
- Strings (text) → always in quotes
- Numbers → never in quotes
Strings (Text) — Always Use Quotes
let firstName = "Emma";
let lastName = "Watson";
let favoriteColor = "blue";
let address = "123 Main Street";
Anything in quotes is a string (text).
Numbers — Never Use Quotes
let age = 30;
let price = 9.99;
let temperature = -5;
let score = 0;
Numbers are written without quotes. They can be:
- Whole numbers:
42 - Decimals:
3.14 - Negative:
-10
⚠️ Critical Difference
let textNumber = "25"; // This is TEXT, not a number!
let realNumber = 25; // This is an actual NUMBER
// Why does it matter?
console.log("25" + "25"); // "2525" (joins text)
console.log(25 + 25); // 50 (adds numbers)
Real-World Example
// A user profile
let username = "gamer123"; // Text - it's a name
let level = 15; // Number - for calculations
let coins = 500; // Number - for calculations
let email = "gamer@email.com"; // Text - it's an address
Your Turn!
Create two variables:
usernamecontaining the text "Player1"scorecontaining the number 100