调用我的函数后,我很惊讶我的函数没有抛出错误,因为有一个变量并且使用了一个未在函数范围内定义的变量。
我的问题:为什么我的函数不抛出未定义、错误等?它不应该因为“长度”不在我的函数参数中而引发错误吗?我知道,如果我将“长度”切换为“高度”,它将起作用。
如果有人可以逐步解释javascript如何解释这个函数,这将对我有所帮助。这是我的代码:
function areaRectangle(width, height) {
aRectangle = width * length;
console.log("The area of the rectangle is: " + aRectangle);
}
areaRectangle(10, 7); # The area of the rectangle is: 0