Closures & Scope

Scope Chain Lookup

Scope Chain Lookup

The scope chain is the path JavaScript follows when code reads a variable name. It checks the current function first, then moves outward through the places where the function was written.

That means the caller does not decide which outer variable is used. The source code structure decides it.

Your task: Read the commented code in the starter. Predict the value returned by showRole(), and assign that string to prediction.

Prerequisites

  • variables
  • strings
  • functions

Tests

  • prediction matches the value found in the nearest scope
  • prediction is a string
Loading...
Console

Run code to see output.

Previous1 / 20Next