Why is a negative case in try catch block returning 'Undefined'
Created 3 years ago
28
Views
2
Comments
When I try to get value of a key not there in map in the try catch block why is it throwing undefined.
I can check if the map has the key with has() method but why is the below code throwing undefined instead of printing the log as "Error"
var n="0";
try{
var monthDaysMap = new Map([
["1","31"],
["2","28"],
["3","31"],
["4","30"],
["5","31"],
["6","30"],
["7","31"],
["8","31"],
["9","30"],
["10","31"],
["11","30"],
["12","31"]
]);
console.log(monthDaysMap.get(n));
}catch(error){
console.log("Error");
}