Question · JavaScript and TypeScript course · Module 2: Functions, Arrays and Objects
Lexical Scope of Variables
What will we see in the console after running the following code?
function outer() { const x = 10; function inner() { console.log(x); } inner(); } outer();
Answer options
- undefined
- 10 - the inner function sees variables from the outer scope
- null - variable x was not passed as an argument
- ReferenceError - x is not defined
Show the answer
Correct answer:
- 10 - the inner function sees variables from the outer scope