Skip to content

JavaScript Tutorial Variables and Values

JavaScript Variables

Lesson 10 of 258 2 min read By Deepak Paswan Updated Oct 4, 2026

A variable is a name for a value. Think of a labelled box: you put something in, and later you can open the box by its label.

script.js
JS
let score = 10;
console.log(score); // → 10

score = 15;
console.log(score); // → 15

let score = 10; does two things in one line: it declares the variable (creates the box and names it score) and assigns a value to it (puts 10 inside). On the next line, score = 15; assigns a new value. There is no let the second time, because the box already exists.

Why variables matter

Without variables, you would repeat the same value everywhere in your code. With one, you change it in a single place.

script.js
JS
const taxRate = 0.2;
const price = 50;

console.log(price * taxRate); // → 10
console.log(price + price * taxRate); // → 60

Declare first, assign later

You can declare a variable without a value. It holds undefined until you give it one.

script.js
JS
let message;
console.log(message); // → undefined

message = "Hello";
console.log(message); // → Hello

Variables can hold anything

Numbers, text, true or false, lists, objects, even functions. You will meet each of these in the next lessons and chapters.

info
Three keywords
JavaScript has let, const and var for declaring variables. They behave differently, and the next lessons explain when to use each: let and const and var.