The console log shows me "active" but the "blocks" variable is still false and shows me "not active" in the alert.
var blocks = false;
(function(){
var test = document.createElement('div');
test.innerHTML = ' ';
test.className = 'adsbox';
document.body.appendChild(test);
window.setTimeout(function() {
if (test.offsetHeight === 0) {
var blocks = true;
console.log("active");
} else {
var blocks = true;
console.log("not active");
}
test.remove();
}, 200);
})();
Here the check if the variable is true:
if (blocks) {
alert('active');
}else{
alert('not active');
}
Why is "block" always false and how can I use the "block" variable after the function?