Course contentsShow
← Computer Science
Lesson 138 of 2,8724. Introduction to ProgrammingFree lesson

What is a Variable?

Understanding variables as named storage locations that hold values during program execution.

What is a Variable?

You'll learn: What variables are and why they're essential building blocks in every program.

The Core Idea

A variable is a named storage location in a computer's memory that holds a value while your program runs. Think of it like a labeled box: you give it a name (the label), and you can put something inside it (a value). Later, you can look at what's in the box, change it, or use it in calculations.

Just as you might have a box labeled "Birthday Cards" that holds cards today but could hold letters tomorrow, a variable has a fixed name but can store different values at different times during program execution.

Why Variables Matter

Without variables, programs couldn't remember anything. Every calculation, every piece of user input, every intermediate result needs somewhere to live temporarily. Variables give you that "working memory."

For instance, if you're writing a program to calculate the area of a rectangle, you need places to store:

  • The length value
  • The width value
  • The computed area

Each of these would be a variable with a meaningful name like length, width, and area.

Key Properties

  1. Name: A label you choose (like score or userName)
  2. Value: The data currently stored (like 42 or "Alice")
  3. Type: What kind of data it holds (number, text, true/false, etc.)

Variables bridge the gap between abstract logic (the math and algorithms you've learned) and concrete computation (making the computer actually do something with data).

Key Takeaway: Variables are named containers that store values during program execution, giving programs the ability to remember and manipulate data.