The result of the code below is Cat and undefined. *If the key does not exist, 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 result of the below code is "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 the key have an ordinal number which doesn't exist, How to get an "undefined" ?