What are Variables and Data Types?
A variable is a named storage location a program uses to hold a value, and its data type tells the computer what kind of value it can hold and what operations are valid on it. Understanding both is the first step to writing any working program.
A variable is a labeled container that stores a value in memory, and a data type (like integer, string, or boolean) defines what kind of value it holds and how it can be used.
- •Value can change while the program runs
- •Declared with let / var
- •Used for data that updates, like a counter or score
- •Value is fixed after it is first set
- •Declared with const / final
- •Used for data that never changes, like pi or a tax rate
Step-by-step worked examples
Declare a variable that stores a person's age as a whole number.
Choose a name: age Choose a type: integer (whole number) Assign a value: age = 27 Result: age now holds the integer 27
Store a user's name as text.
Choose a name: userName Choose a type: string (text) Assign a value: userName = "Elif" Result: userName holds the string "Elif"
Track whether a light switch is on or off.
Choose a name: isOn Choose a type: boolean (true/false) Assign a value: isOn = true Result: isOn holds the boolean true, showing the light is on
Flashcards
Quick quiz
Q1.Which of these is a valid variable declaration storing a whole number?
Q2.What data type would you use to store true or false?
Q3.Which best describes a data type?
Q4.What happens if you try to add a string and an integer directly in most strongly typed languages?
The full card deck, worked steps and AI-tutor support for “What are Variables and Data Types?” are in Notek — study by hand before your exam.
Common mistakes
Thinking a variable's type can never change once declared, in every language. — Correct: In statically typed languages the type is fixed, but many languages (like Python or JavaScript) are dynamically typed and allow the type to change.
Storing numbers as text, e.g. age = "27". — Correct: Use a numeric type (integer/float) for numbers so you can do math on them without extra conversion.
Using vague variable names like x or data1. — Correct: Use descriptive names like studentAge so the code documents itself.
Confusing a variable's name with its value. — Correct: The name is a label; the value is what's actually stored and can change over time.
FAQ
What is a variable in programming?
A variable is a named piece of memory that stores a value your program can read, use, and change while it runs.
What are the main data types?
The most common are integer (whole numbers), float (decimals), string (text), and boolean (true/false).
What is the difference between a variable and a data type?
A variable is the named container; the data type is the category of value it's allowed to hold, like integer or string.
Why are data types important in programming?
They catch errors early, control memory usage, and determine which operations (like addition or concatenation) are valid.




