Constant

A constant is a named value that cannot be changed once it is set. It is used for values that should stay fixed, such as PI or a maximum limit.

General Programming

Using constants makes code clearer and prevents accidental changes. By convention, constant names are often written in UPPERCASE.

Examples

JavaScript

const MAX_USERS = 100;
console.log(MAX_USERS);
// MAX_USERS = 200; // would throw an error

Output:

100

Python

PI = 3.14159   # constant by convention
print(PI)

Output:

3.14159

See also

Back to the Dictionary