🎓 Prepared by students from Boğaziçi University

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.

Short answer

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.

Variable vs. Constant
Variable
  • Value can change while the program runs
  • Declared with let / var
  • Used for data that updates, like a counter or score
Constant
  • Value is fixed after it is first set
  • Declared with const / final
  • Used for data that never changes, like pi or a tax rate
01

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
02

Flashcards

03

Quick quiz

Q1.Which of these is a valid variable declaration storing a whole number?

Correct answer: A. 27 is a whole number, so it matches the integer data type.

Q2.What data type would you use to store true or false?

Correct answer: C. Boolean stores exactly two values: true and false.

Q3.Which best describes a data type?

Correct answer: B. A data type classifies the kind of value stored, such as integer or string.

Q4.What happens if you try to add a string and an integer directly in most strongly typed languages?

Correct answer: B. Strongly typed languages flag mismatched types as an error unless you convert explicitly.
📄Download this topic as a printable worksheet (PDF)Summary + 10 questions + answer key — print it, share it in class.
Study better with Bounlu apps
Notek
Notek

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.

Get it free
Notek 1Notek 2Notek 3Notek 4Notek 5
04

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.

05

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.

Related topics