I made this variable "generateError" to not work on purpose but I encounter this same issue in another context when checking for keys in an array. So my question, how do I get the variable status to just show "array not working" instead of generating error code?
var numbers = [1, 2, 3, 4];
var generateError = numbers['badKey'][2];
if (typeof(generateError)==undefined){
var status=("array not working");
}
else
{
var status=("array is working");
}
document.getElementById("status").innerHTML=status;
<div id="status"></div>