Programming Basics
What Is a Variable in Programming?
A variable is a named place in memory that stores a value, such as a number or some text, which your program can read and change.
Definition
A variable is a name that refers to a value stored in memory. You create it by assigning a value, then use the name wherever you need that value.
As the name suggests, the value can vary: you can assign a new value later.
How it works
In statically typed languages such as Java and C#, you declare the type along with the variable (int age = 30), and it cannot hold another type. In dynamically typed languages such as Python and JavaScript, the type comes from the current value.
Scope decides where a variable can be used. A variable created inside a function is local to it; one created at the top level of a file is global.