Loading workspace environment...
Master variables: the labeled storage boxes of computer memory.
const name = "Alice";Creates a constant variable that cannot be reassigned.let score = 0;Creates a mutable variable that can change over time.score = score + 10;Reassigns a new value to an existing variable.const playerName = "Neo";
let playerLevel = 1;
let healthPoints = 100;
console.log("Player:", playerName);
console.log("Level:", playerLevel);
console.log("Health:", healthPoints);
// Player takes damage and levels up:
healthPoints = healthPoints - 25;
playerLevel = playerLevel + 1;
console.log("--- AFTER BATTLE ---");
console.log("Level:", playerLevel);
console.log("Health:", healthPoints);Player: Neo
Level: 1
Health: 100
--- AFTER BATTLE ---
Level: 2
Health: 75const playerName = "Neo";Creates an immutable binding for the player name.healthPoints = healthPoints - 25;Updates the value stored in healthPoints from 100 to 75.const age = 20;
age = 21; // TypeError: Assignment to constant variablelet age = 20;
age = 21; // Works because "let" permits reassignmentArchitectural Explanation: Variables declared with const cannot be reassigned. If a value needs to change, use let.
const points = 10;
points = 20;
console.log(points);Create a bank balance variable starting at $500. Add a deposit of $150, subtract a withdrawal of $40, and log the final balance.