A constant is like a variable, except its value can never change after it's set. Use a constant whenever a value should stay fixed for the life of the program — it protects you from accidentally overwriting something you didn't mean to.
In JavaScript, use const instead of let:
const pi = 3.14159;
const siteName = "Learn Computer Academy";
console.log(pi); // 3.14159<?php
define("PI", 3.14159);
define("SITE_NAME", "Learn Computer Academy");
echo PI; // 3.14159PI = 3.14159
SITE_NAME = "Learn Computer Academy"
print(PI) # 3.14159Trying to reassign a constant is an error — JavaScript stops you on purpose (PHP and Python each handle this differently — see the other tabs):
const pi = 3.14159;
pi = 3.14; // ❌ TypeError: Assignment to constant variable.<?php
define("PI", 3.14159);
define("PI", 3.14); // ❌ Warning: Constant PI already definedPI = 3.14159
PI = 3.14 # ⚠️ Python has no real constants — ALL_CAPS is only a
# naming convention, nothing stops the reassignment.A common habit among experienced programmers: default to const, and only switch to let when you know a value genuinely needs to change later (like a counter or a score). It makes code easier to reason about — if you see const, you know that value is fixed for good.