Variables And Constants in javascript

JavaScript variables are used to store values in memory. Use let for reassignable values, const for values that should not be reassigned, and avoid var in modern code because of its function scope and hoisting quirks.

Example

let counter = 0;      // can be reassigned
const API_URL = "/api"; // should not be reassigned

// BAD: var is function‑scoped and hoisted
function demo() {
  console.log(x); // undefined
  var x = 10;
}

Prefer let and const for predictable block scoping; var behaves differently because it is function‑scoped and hoisted.