vendredi 6 novembre 2020

The if statement in JS does not function as it should when looking for null

I am running my code in expo and for some reason the if statement does not work as it should. Below is my code:

const FirebaseProfileUpdate = async (type, userID, information) => {
    // new account
    let pullData;
    pullData = await getData(userID);
    console.log('data is', pullData);
    const returnMainCreateProfile = await createUser(pullData);
    return returnMainCreateProfile;
  }

and the other function I am calling is:

const createUser = async (pullData) => {
  let didPushUser;
  console.log('in create user', pullData);

  if (pullData === null) {
    // user doesnot exist
    console.log('1', pullData);
    didPushUser = await pushUser(userID, information);
  } else if (pullData !== null) {
    console.log('2', pullData);
    // console.log('Sorry, that userID already exists');
    didPushUser = 'Unsuccessful';
  }

  console.log('end of user create');
  return didPushUser;
};

You would think when when the pullData is null it should print 1 but it doesn't! I cannot figure out why!! Below is what I get in my console after running this code:

data is null
in create user null
2 null
end of user create

Aucun commentaire:

Enregistrer un commentaire