JavaScript Basics & Variables
1 min read2 lessons in topic
Learning objective
By the end of this lesson you will be able to store values in JavaScript variables and print messages to the console.
JavaScript is the programming language of the web. It runs in every browser and lets you make pages interactive.
Your first JavaScript
console.log("Hello from JavaScript!");console.log prints a message to the browser's developer console (press F12 to open it).
Variables
let name = "Ama";
const age = 21;
console.log(name); // Ama
console.log(age); // 21let declares a variable that can change later; const declares one that cannot be reassigned.
Data types
- String — text, e.g. "hello"
- Number — e.g. 42 or 3.14
- Boolean — true or false
- null — an intentionally empty value
- undefined — a variable with no value yet
let score = 87;
const passed = score >= 50;
console.log("Score:", score, "Passed:", passed);Code playground
Run and edit the starter code — experiment freely.
javascript · runnable
Output appears here when you press Run.
Practice exercise
Declare your name and your age, then print a sentence that uses both.
Check your understanding
1. Which keyword declares a value that cannot be changed?
2. How do you print a message to the browser console?
Self-graded — answer then check below.