在 JavaScript 中設定可選函式引數的最佳方法是什麼?
若要包含 JavaScript 中的可選函式引數,可嘗試以下方法,
function myFunc(a, b = 0) {
// function body
}示例
可以嘗試執行以下程式碼,瞭解如何包含可選函式引數 −
<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>
廣告
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP