Computer ScienceProgrammingEasy

Variable (Programming)

Also known as:identifierbindingname binding

A variable is a named storage location in a program's memory that holds a value which can be read or modified during execution. Variables allow programmers to store, retrieve, and manipulate data dynamically without hardcoding fixed values. They are fundamental to all programming paradigms, enabling algorithms to operate on different inputs and maintain state across instructions.

Variable Declaration Syntax Across Popular Languages

LanguageDeclaration KeywordExampleTyped?
PythonNone (implicit)x = 10Dynamic
JavaScriptlet / const / varlet age = 25;Dynamic
JavaType before nameint score = 100;Static
C++Type before namedouble pi = 3.14;Static
Kotlinval / varvar name = "Arjun"Inferred

Interactive Tools

Codecademy – Variables Lesson

Open Tool

Khan Academy – Intro to Variables

Open Tool

Brilliant – Programming Fundamentals

Open Tool
Diagram showing a variable as a labelled box holding a value in memory

Wikimedia Commons, CC BY-SA

Related Terms

Computer Science

Data Type

A data type is a classification that specifies the kind of value a variable can hold, the operations that can be performed on it, and how its binary representation is stored in memory. Common primitive data types include integers, floating-point numbers, characters, and booleans, while composite types include arrays, strings, and objects. Choosing the correct data type is essential for memory efficiency, performance, and preventing logical errors in programs.

Computer Science

Object-Oriented Programming

Object-Oriented Programming (OOP) is a programming paradigm that organises software design around data, called objects, rather than functions and logic. Each object encapsulates data (attributes) and behaviour (methods), and objects interact with one another to build complex systems. The four core principles of OOP — encapsulation, inheritance, polymorphism, and abstraction — promote code reusability, modularity, and maintainability.

Computer Science

Encapsulation

Encapsulation is the OOP principle of bundling an object's data (attributes) and the methods that operate on that data into a single unit (a class), while restricting direct external access to the internal state. By declaring attributes as private and exposing them only through public getter and setter methods, encapsulation enforces data integrity and hides implementation details. This protects objects from unintended interference and simplifies maintenance since internal changes do not affect external code.

From Latin "variabilis" meaning "changeable", derived from "variare" (to vary). In mathematics and later computing, the term was adopted to describe a quantity that can take different values, contrasted with a constant.

variablesmemoryprogramming-basicsstateidentifier