Why doesn't this function throw an error if the remaining arguments are missing?
showStatistics("Mark Teixeira", "New York Yankees", "1st Base");
Here is a the function defined:
function showStatistics(name, team, position, average, homeruns, rbi) {
document.write("<p><strong>Name:</strong> " + arguments[0] + "<br />");
document.write("<strong>Team:</strong> " + arguments[1] + "<br />");
if (typeof arguments[2] === "string") {
document.write("<strong>Position:</strong> " + position + "<br />");
}
if (typeof arguments[3] === "number") {
document.write("<strong>Batting Average:</strong> " + average + "<br />");
}
if (typeof arguments[4] === "number") {
document.write("<strong>Home Runs:</strong> " + homeruns + "<br />");
}
if (typeof arguments[5] === "number") {
document.write("<strong>Runs Batted In:</strong> " + rbi + "</p>");
}
}
typeof undefinedreturns"undefined", which is not an exception.undefinedin the function body. It may crash if you run a piece of code that would crash on anundefinedobject. Testing whethertypeof undefined === 'string'is not one of these pieces of code.