var jFunc = function() {
var q;
var p = 0;
q = (typeof(q) === "undefined") ? 0 : q;
p += 1;
q += p;
console.log(q);
};
In the console of chrome developer tools, the output of console.log(q) is q + 1 (1, 2, 3, 4, and so on..) every subsequent iteration of running the entire block of code within jFunc independently of invoking jFunc. However, when invoking jFunc (so as to conveniently avoid copying and pasting the code block within the console), the output is always 1 everytime. Why is this the case?
The goal is to essentially save a numeric value to a variable, add 1 to it, and return it without the use of global variables.