Question 1
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const level = "global";
function show() {
return level;
}
function run() {
const level = "local";
return show();
}
console.log(run());
- A local
- B undefined
- C global Correct
- D ReferenceError
Correct Answer: Option C
Scope is lexical: show() was written at the top level, so it reads the top-level level, no matter that run() calls it.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!