Skip to content
BENIBIX Learn

Constant

Development🧩 Programming ConceptsData and Variables

A named value that never changes. It stays the same the whole time a program runs.

Think of it like

Think of it like the days in a week. There are always seven, and nobody changes that.

Example

A shop sets TAX_RATE to 0.2 once, at the top. Every price uses it, so a new rate is a change to one line.

Why it matters

A value written once in a constant is changed in one place. The same number typed in ten places gets missed in one.

Definition

A constant names a value that never changes while a program runs. Tax rates, the number of days in a week and a site's address are common ones. Some languages, like JavaScript, stop you if you try to change a constant. Others, like Python, only ask you to write the name in capitals. Either way, a constant tells the reader to leave this value alone.

Example code

javascript
const TAX_RATE = 0.2;
TAX_RATE = 0.3;
// TypeError: Assignment to constant variable.
JavaScript says no to the second line, since the value is fixed.

Common mistake

Typing the same number all over the code. When it changes, one copy always gets left behind.

Key takeaways

  1. 1
    Set once. The value is given at the start and kept.
  2. 2
    One place to change. Edit one line, and every use follows.
  3. 3
    Capital names. Many teams write constants like TAX_RATE.

Learn it properly