为什么在编写函数时有时需要在括号内编写有时不需要?例如 function get arr()
与 function get max(arr)
。
谢谢,
一个
最佳答案
当你在括号内调用一个函数时,你就是在传递参数。
当你不传递任何东西时,你只需将括号留空,就像这样 ()。
例如:
function add(a,b){ //passing arguments
return a+b;
}
add(15,13); // returns 28
function name(){ //not passing arguments
return 'hello world';
}
name(); // returns 'hello world'
在第二种情况下,您将函数作为参数传递给另一个函数。
如果您需要更多信息,请发表评论,因为您的问题不是很清楚您想问什么。
关于javascript - 编写函数时使用括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39429828/