I am trying to set a variable initially only if it has not been set. For some reason the logic I'm using to determine whether the variable has been set seems to run even regardless of whether the variable has been set.
My code is
var l0 = -210;
function add(){
var lThis;
if (lThis == null){
lThis = l0;
console.log('set lThis to '+ lThis);
}
lThis ++;
}
var incrementInterval = setInterval(add, 33);
The console logs "set lThis to -210" every time the interval runs, so the "if (lThis == null)" seems to be doing nothing