JavaScript函数中的可选参数是什么?
要在JavaScript中声明可选函数参数,请使用“默认”参数。
示例
你可以尝试运行以下代码来声明可选参数 -
<html>
<body>
<script>
// default is set to 1
function inc(val1, inc = 1) {
return val1 + inc;
}
document.write(inc(10,10));
document.write("<br>");
document.write(inc(10));
</script>
</body>
</html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C编程
C++
C#
MongoDB
MySQL
Javascript
PHP