Variable magically changing values?

I’m having issues getting the following to work… For some reason the variable keeps evaluating as true regardless of the actual value…

====================================
export function inputSearch_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
console.log(session.getItem(“subscribed”));
let searchCheck = session.getItem(“subscribed”);
console.log(searchCheck);
if (searchCheck) {
console.log(“Subscribed for Search”);
search($w(“#inputSearch”).value, true);
} else {
console.log(“NOT Subscribed for Search”);
search($w(“#inputSearch”).value, false);
}
}, 200);
}

=======================================
console log:

false
false
Subscribed for Search

================================================

I should be getting “NOT Subscribed for Search” in the log, but my variable ‘searchCheck’ keeps being evaluated as true in the if statement. What’s going on here?

I believe the problem is that let searchCheck = session.getItem(“subscribed”); returns a string and NOT a boolean value. All values ( session or local ) saved in wix-storage are string values.

I believe that your if statement should be:

if (searchCheck === "true") {

Try this and see if it works for you.

Good luck,

Yisrael

Thank you… That’s working. SImple fix.