Scope of nested functions in JavaScript

If the function contains another function inside - the variables of the outer function are visible in the inner one:

function test() { let num = 1; // the external function variable function func() { console.log(num); // shows 1 } func(); // calls the inner function } test(); // calls the external function

Also, variables defined outside the outer function will be visible in the inner function:

let num = 1; // the global variable function test() { function func() { console.log(num); // shows 1 } func(); // calls the inner function }; test(); // calls the outer function

Determine what will be output to the console without running the code:

function test() { let num = 1; function func() { console.log(num); } func(); } test();

Determine what will be output to the console without running the code:

function test() { let num = 1; function func() { console.log(num); } } test();

Determine what will be output to the console without running the code:

function test() { let num = 1; function func() { console.log(num); } func(); }

Determine what will be output to the console without running the code:

function test() { let num; function func() { console.log(num); } num = 1 func(); num = 2 func(); } test();
enru