How to declare a variable that its value can be changed globally by functions?
var a = 0;
var b = 0;
function c() {a = 5};
function d() {b = 6};
function e() {console.log(a+b)};
c();
d();
e(); // I expect here: 11
How to declare a variable that its value can be changed globally by functions?
var a = 0;
var b = 0;
function c() {a = 5};
function d() {b = 6};
function e() {console.log(a+b)};
c();
d();
e(); // I expect here: 11
Is that what you want? You can find lots of example when you search it.
function count() {
alert(count.num);
count.num++;
}
// initialize count number
count.num = 0;
foo(); // alert 0
foo(); // alert 1