
Coding Education
What Is a Constant in Programming? Definition and Examples

Hafiz Rahman
Lead Coding Instructor at Algonova Malaysia

A constant is a fixed value in a program that never changes while the program runs — the opposite of a variable. Once you set a constant, its value stays the same from start to finish. Programmers use constants for numbers and text that should stay locked, such as the value of pi, the number of days in a week, or a game's maximum score.
Constant vs Variable
A variable is a labelled box whose contents can change; a constant is a box that has been sealed shut. Both store data, but only a variable can be updated later. In Python, programmers write a constant's name in capital letters to signal "do not change me":
PI = 3.14
radius = 5
area = PI * radius * radius
Here PI is a constant — 3.14 never changes — while radius is a variable you might update for a bigger circle. In Scratch, a constant is like a number you type directly into a block, while a variable sits inside a named block you can change at any time. Fun fact: many languages, such as JavaScript and C++, have a special keyword (const) that stops a constant from being changed by mistake.
Why It Matters for Kids
Understanding constants helps children write clearer, safer code and see the difference between data that stays put and data that moves — a core idea in STEM and Malaysia's KSSR computational-thinking lessons. Constants also make programs easier to read and fix. Kids can practise this hands-on in Algonova coding classes, and it pairs naturally with learning what a variable is.
Curious minds can try a free trial class and write their very first constant.

