I have tried declaring the variable outside the function but I get undefined.
function scope() {
let foo = 1;
const bar = function() {
return ++foo;
}
return bar;
}
const baz = scope();
console.log(baz.foo);
console.log(baz.foo);