jeudi 29 octobre 2020

Page reading 2 different If-Statements as the same

I'm running into a pretty confusing situation here:

   if ((a.length == 0 || b === null)) {
        this.noNotif = true;
        console.log("1");
      }
      if (a.length > 0 || b === null) {
        this.newNotif = true;
        // this.noNotif = false;
        console.log("2");
      } else {
        if (a.length === b.length) {
          console.log("No New Notifications");
          this.noNotif = true;
        } else {
          console.log("New notifications");
          this.newNotif = true;
        }

Console logging a.length returns 0 and 'b' is null However, the issue is that somehow both of the first two if-statements' conditions are being met. noNotif and newNotif both display a Vue components and both are showing up currently.

Some background information about a & b

'a' is supposed to be data from an API that is fetched on page load. 'b' is supposed to be a localStorage object array

The first if-statement deals with a new user who has no API data or anything stored in LocalStorage

The second if-statement handles when the user does have data in the API, but nothing in LS yet.

The First nested if-statement is if the data from the API matches the LS data

The nested else-statement is if the API data is different (longer) than what's in LS

Aucun commentaire:

Enregistrer un commentaire