JS
challenger
Home
Intermediate JavaScript
scope
Update an outer variable from a nested function
Update an outer variable from a nested function
A nested function can also update variables in an outer scope. Inside
inner
, increment the global
counter
by 1 so the final logged value is 1.
Premium
reset
function greet(name) { return `Hello, ${name}!`; } console.log(greet("Erik"));
JavaScript
Run Code
Console