bhylu.com

Advertisements

JS Scope

Scope decides where a name can be used. A function can read names from the surrounding scope.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

const club = "Repair club";
function label() {
  const day = "Saturday";
  return club + " on " + day;
}
console.log(label());

What happens

Both names are available inside label.