Variable (programming)
A variable is a named container that stores data in a program, allowing that data to change during execution. Think of it as a labeled box: you give it a name (like score or username), assign it a value, and later retrieve or modify that value as your program runs.
Variables are fundamental to computation. Every algorithm relies on them to hold intermediate results, track state, and respond to data dynamically. The concept bridges mathematical variables and practical computing: where a mathematician asks "what value satisfies this equation?", a programmer declares "this name will hold whatever value I put in it."
Most programming languages require you to declare variables before use, specifying a data type (integer, text, floating-point number, etc.). Some languages like JavaScript are more flexible, inferring types automatically. Modern languages also enforce scope—rules about where a variable exists and can be accessed—to prevent chaos in large programs.
Variables enable branching, loops, and functions to work. Without them, programs would be rigid sequences with no memory or adaptability.
Related
Data type, Assignment (programming), Scope (programming), Memory (computing), State (computer science)