I tried this:
var count;
function testCount ()
{
if (count)
{
alert("count is: " + count);
count++;
}
else
{
alert("count is: " + count);
var count = 0;
}
};
testCount();
but it always gives “undefined” and the value of count is not updated when I run it again in jsfiddle.
It appears that nobody has shown the simple
testCount()implementation. Just initialize it upon declaration and then just use it in your function: