Closures & Scope

Function Scope

Function Scope

Function scope means variables declared inside a function belong to that function call. Code outside the function cannot read those local variables directly.

When outside code needs a value produced inside a function, the function should return it. That keeps the data flow visible and avoids reaching across a scope boundary.

Your task: Fix buildLessonLabel so it returns the label it creates. Then store the call result in lessonLabel and log it.

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.

Function Scope

Function scope means variables declared inside a function belong to that function call. Code outside the function cannot read those local variables directly.

When outside code needs a value produced inside a function, the function should return it. That keeps the data flow visible and avoids reaching across a scope boundary.

Your task: Fix buildLessonLabel so it returns the label it creates. Then store the call result in lessonLabel and log it.

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.