In the realm of programming, constants and literals are fundamental building blocks that play a crucial role in constructing robust and reliable software applications. Understanding the distinction between these two concepts and employing them effectively is essential for aspiring software engineers.
xxxxxxxxxx
20
// Constants
const MAX_SIZE = 100; // Maximum size for an array
const PI = 3.14159; // Value of pi
const GRAVITY = 9.81; // Acceleration due to gravity
// Literals
let name = "Alice"; // String literal
let age = 30; // Numeric literal
let isActive = true; // Boolean literal
// Driver code to demonstrate the usage of constants and literals
console.log("Constants:");
console.log("Maximum size:", MAX_SIZE);
console.log("Value of pi:", PI);
console.log("Acceleration due to gravity:", GRAVITY);
console.log("\nLiterals:");
console.log("Name:", name);
console.log("Age:", age);
console.log("Is active:", isActive);
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment