JavaScript 中函数参数的默认参数是什么?
javascriptweb developmentfront end technology更新于 2026/2/2 17:16:17
默认参数可以轻松处理函数参数。您可以轻松设置默认参数,以允许使用默认值初始化形式参数。这仅在未传递任何值或未定义时才有可能。
示例
<html>
<body>
<script>
// 默认值设置为 1
function inc(val1, inc = 1) {
return val1 + inc;
}
document.write(inc(10,10));
document.write("<br>");
document.write(inc(10));
</script>
</body>
</html>
相关文章
有用资源
javascript 参考教程 - 该教程包含有关 javascript 的更多信息:https://www.cainiaomax.com/javascript/

