Variables & Numbers
Loading simulation…
flagWhat you'll discover
- arrow_forwardPrint values to the console with console.log()
- arrow_forwardDeclare variables with let and const
- arrow_forwardUse arithmetic operators on numbers and variables
- arrow_forwardRead console output to understand what your code did
The console is your laboratory
Every browser hides a programmer's playground called the console. console.log() prints anything you give it — text, numbers, calculations — into that panel. It may look humble, but the console is the number one debugging tool in the world: when professionals wonder what their code is doing, they log values and look. In this lesson the console is your whole world. Type an instruction, press Run, read the output. That tight loop — write, run, read — is how all programming works.
Variables are labelled boxes
A variable stores a value under a name: let score = 100 creates a box labelled score holding 100. Use the name anywhere and JavaScript opens the box: console.log(score + 25) prints 125. Use let for values that will change and const for ones that never should — the browser will actually stop you from overwriting a const, which catches bugs early. Choose names that say what they hold: playerScore beats x when you read your code next week.
JavaScript is a calculator with memory
The operators + - * / work like your maths class, with * for times and / for divide. The percent sign % is the remainder operator: 10 % 3 gives 1, the leftover after dividing — surprisingly useful for things like "is this number even?" Combine operators with variables and you get living formulas: price * quantity, seconds / 60. Unlike a pocket calculator, JavaScript remembers every result you store, so calculations can build on each other line after line.