JavaScript 中的默认函数参数是什么?
javascriptweb developmentfront end technology
默认参数可以轻松处理函数参数。您可以轻松设置默认参数,以允许使用默认值初始化形式参数。这仅在未传递任何值或未定义时才有可能。
示例
让我们看一个例子 −
<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>