Variable

A variable is a named container that stores a value in a program's memory. The value it holds can change as the program runs.

General Programming

Variables are the most fundamental building block in programming. You give a value a name so you can refer to it, reuse it, and update it later without repeating the value itself.

Every variable has a name (an identifier) and a value. In statically-typed languages it also has a fixed type; in dynamically-typed languages like Python and JavaScript the type is inferred from the value and can change.

Syntax

name = value

Examples

Python

score = 0
score = score + 10
print(score)

Output:

10

JavaScript

let score = 0;
score = score + 10;
console.log(score);

Output:

10

Java

int score = 0;
score = score + 10;
System.out.println(score);

Output:

10

Learn it in a lesson

See also

Back to the Dictionary