2020-10-30

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



from Recent Questions - Stack Overflow https://ift.tt/31SBRC8
https://ift.tt/eA8V8J

No comments:

Post a Comment