JS Built-ins
Variablesbeginner

Variables β€” let: block-scoped

let is block-scoped

A let variable is only accessible within the block { } where it was declared. A new let x inside a block creates a separate variable.

Challenge: Write blockScope() that:

  1. Declares let x = 'outer'
  2. Opens a block { } and declares let x = 'inner' inside it
  3. Returns x (should be 'outer' β€” the block's x doesn't escape)
πŸ’‘ Hints (1)
  • β€’ let is confined to the { } block where it was declared