function make_withdraw(balance) {
return function(amount) {
if (balance >= amount) {
balance = balance - amount;
return balance;
} else {
return "Insufficient funds";
}
}
}
var W1 = make_withdraw(100);
W1(50); // 50
W1(60); // "Insufficient funds"
W1(40); // 10
function w(amt){
var b= 100;
if(b>=amt){b=b-amount;return b;}else{return alert("error!");}}
w(10); //90
w(10); //90
Why by assigning balance the W1 function can keep track of balance, while w function cannot?