Skip to content

JS Constants

Syntax

Constants in JavaScript are declared using the const keyword and cannot be reassigned after their initial definition.

const CONSTANT_NAME = "value"; // Declare a constant
// CONSTANT_NAME = "new value"; // This would cause an error

Example

const MAX_USERS = 100; // Define a constant for maximum users
console.log(`The maximum number of users is ${MAX_USERS}.`);
// MAX_USERS = 200; // Uncommenting this line would throw an error