Get to know MDN better
此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。
JavaScript 的「redeclaration of formal parameter」例外會在函式參數中出現了相同的變數名稱,且函式主體中又再次使用 let 賦值來重複宣告它時發生。
當函式參數中出現了相同的變數名稱,且函式主體中又再次使用 let 賦值來重複宣告它時,就會發生此錯誤。JavaScript 不允許在相同的函式或區塊作用域中,使用 let 重複宣告相同的變數。
在這個例子中,變數「arg」重複宣告了引數。
如果你想在函式主體中改變「arg」的值,你可以這麼做,但你不需要再次宣告相同的變數。換句話說:你可以省略 let 關鍵字。如果你想建立一個新的變數,你需要將它重新命名,以避免與現有的函式參數衝突。
This page was last modified on 2025年7月21日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.