A bit of an old thread, but I had this happen when I initialised the variable with false
let tab_clicked = false;
tab_clicked = document.querySelector("button");
if (tab_clicked) {
// DID NOT WORK
}
let tab_clicked = '';
tab_clicked = document.querySelector("button");
if (tab_clicked !== '') {
// DID WORK :D
}