Let's say I have two api calls that returns a list of objects
const userResult1 = {1: {..} ,2: {..} 3: {..}}
const userResult2 = {3: {..} ,4: {..} 5: {..}}
either one could return null. What I'm currently doing is:
if (userResult1 || userResult2 === null) {
//false
} else {
const dataset = [
Object.keys(userResult1 ),
Object.keys(userResult2 ),
];
const result = checkIfDuplicateExists(dataset);
console.log(result) //true or false
}
I did not have the if statement before which used to throw Cannot convert undefined or null to object
but adding the if statement prevents this. Is this a good approach?