Closures & Scope

Variable Shadowing

Variable Shadowing

Variable shadowing happens when an inner scope declares a name that also exists in an outer scope. Reads inside the inner scope use the nearest matching name.

The outer variable still exists. It is shadowed only from the point of view of code inside the inner scope.

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

Free with a JS Exercises account

Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.

By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.

Variable Shadowing

Variable shadowing happens when an inner scope declares a name that also exists in an outer scope. Reads inside the inner scope use the nearest matching name.

The outer variable still exists. It is shadowed only from the point of view of code inside the inner scope.

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

Free with a JS Exercises account

Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.

By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.

Console

Run code to see output.