The output of the code snippet below is "Cat" and undefined. *When a key does not exist in an object, the result will be "undefined".
var animals = {"mammals": ["Cat", "Dog", "Cow"]};
var groupA = animals.mammals[0];
var groupB = animals.birds;
console.log(groupA);
console.log(groupB);
However, the following code results in an error instead of "undefined".
*Uncaught TypeError: Cannot read properties of undefined (reading '0')
var animals = {
"mammals": ["Cat", "Dog", "Cow"]
};
var groupA = animals.mammals[0];
var groupB = animals.birds[0];
console.log(groupA);
console.log(groupB);
If a key contains an index that does not exist, how can we return "undefined"?