Programming Concepts Tutorial

Learn the fundamental concepts of computer programming

Constants

Constants

A constant is similar to a variable, but with one crucial difference: its value cannot be changed once it has been assigned.

Why use Constants?

Constants are used to store values that should remain the same throughout the execution of a program, such as the value of Pi (3.14159), the number of days in a week, or a database configuration URL.

Using constants prevents accidental changes to important data and makes your code easier to read.

Try It Yourself

Edit the code below and click Run to see the result live.

Source Code
Result
Topics