JavaScript Variables: const, let, and Scope

Last updated: August 27, 2026.

Use const unless a binding must be reassigned; use let for a value that changes.

const siteName = "WebCheatSheet";
let pageViews = 0;
pageViews += 1;
console.log(`${siteName}: ${pageViews}`);
const discount = 0.1;
if (discount > 0) {
  const label = "Sale";
  console.log(label);
}
// label is not available here.

const prevents reassignment; it does not make an object deeply immutable.

admin

admin

Leave a Reply

Your email address will not be published.