let x = 1;
function createSum(){
return function(){
return x + 5;
}
}
function foo(){
let x = 5;
return createSum()();
}
function bar(){
let x = 50;
return createSum()();
}
console.log(foo()); // 6
console.log(bar()); // 6
let x = 1;
function createSum(x){
return x + 5;
}
function foo(){
let x = 5;
return createSum(x);
}
function bar(){
let x = 50;
return createSum(x);
}
console.log(foo());
console.log(bar());
let x = 1;
function createSum(){
return function(){
return x + 5;
}
}
function foo(){
x = 5; // del let
return createSum()();
}
function bar(){
x = 50; // del let
return createSum()();
}
console.log(foo());
console.log(bar());