The first time someone told me “store that value in a variable,” I nodded like I understood. I had absolutely no idea what they meant.
A variable is one of the most basic things in coding — and once you get it, everything else starts making sense. This guide explains exactly what a variable is, how to create one, and how to use it — in plain English, with real examples.
What Is a Variable in Coding?
How Variables Work — Step by Step
Real-Life Analogy — The Labeled Box

How to Declare a Variable
Create, name, store — here’s how it works in JavaScript and Python.
Declaring a variable just means creating one. You tell the program — “I need a storage box, here’s its name, and here’s what goes inside.”
Declaring Variables in JavaScript
JavaScript gives you three ways to declare a variable — var, let, and const. Use let for values that change and const for values that stay fixed.
let age = 25; // can change later
const country = “USA”; // never changes
Declaring Variables in Python
Python keeps it simple. No special keyword needed — just write the name, an equals sign, and the value. Python figures out the rest automatically.
age = 25 # Python figures it out
country = “USA” # just name = value
var vs let vs const — What’s the Difference?
| Keyword | Can Change? | When to Use | Status |
|---|---|---|---|
| var | ✅ Yes | Old JavaScript — avoid as a beginner | Avoid |
| let | ✅ Yes | When the value needs to change | Use This |
| const | ❌ No | When the value stays the same | Best Practice |
const. If you need to change the value later, switch to let. Avoid var for now.What Are Constants in Coding?
Like a variable — but the value is locked forever.
A constant is like a variable — but with one rule: once you set its value, you cannot change it.
Difference Between a Variable and a Constant
A variable can be updated anytime. A constant is locked the moment you set it. Try to change it and your program throws an error.
score = 20; // ✓ works fine
PI = 5; // ✗ error!
When to Use a Constant
const. It protects your data from accidental changes.Variable Naming Rules Every Beginner Must Know
Rules You Must Follow
_, or $1name is invalidcamelCase or snake_caselet, if, returnname and Name are different variablesBest Practices for Naming Variables
let totalPrice;
let isLoggedIn;
let maxRetries;
let a1;
let temp;
let data;
Variable Scope — Local vs Global
Where you create a variable decides where you can use it.
Scope means — where in your program a variable can be used. Not every variable is available everywhere. Where you create it decides where you can use it.
Global Variables
A global variable is created outside any function. It can be used anywhere in your program — from top to bottom, inside or outside functions.
Local Variables
A local variable is created inside a function. It only exists inside that function. Try to use it outside — your program throws an error immediately.
FAQs About Variables in Coding
Quick answers to the questions beginners ask most
What are the variables in a code?
let userAge = 25; // another variable
console.log(userName); // prints “Sara”
What are the 4 types of variables in programming?
Can a variable store multiple values?
let colors = [“red”, “blue”, “green”];
// Object — stores key-value pairs
let user = { name: “Sara”, age: 25 };
