Middle+
/* What will be output in the console */ let value = 2; function showValue() { console.log(value); } function wrapper() { let value = 3; console.log(value); showValue(); } wrapper();
sobes.tech AI
Answer from AI
The console will output:
3
2
Explanation:
- In the
wrapperfunction, a local variablevalueis declared with the value 3, and it is immediately logged to the console — this is the first line of output. - Then, the
showValuefunction is called, which accesses the variablevalue. Since there is no local variablevalueinsideshowValue, it looks for it in the outer scope — the global scope, wherevalueequals 2.
Thus, first 3 is output, then 2.