Function parameters redeclared

이 페이지는 아직 한국어로 제공되지 않으며 번역 작업 중입니다. 번역에 관한 질문이나 의견이 있으시면 언제든지 저희에게 연락해 주십시오.

Metadata

ID: javascript-best-practices/no-dupe-args

Language: JavaScript

Severity: Error

Category: Best Practices

Description

In JavaScript, it’s syntactically valid to define multiple parameters with the same name in a function definition. However, doing so is considered bad practice as the last argument value will override the preceding argument value which can lead to issues that are hard to debug.

Non-Compliant Code Examples

function a(a, b, b) {}
function a(a, a, a) {}
function a(a, b, a) {}
function a(a, b, a, b) {}
var a = function(a, b, b) {}
var a = function(a, a, a) {}
var a = function(a, b, a) {}
var a = function(a, b, a, b) {}

Compliant Code Examples

function a(a, b, c){}
var a = function(a, b, c){}
function a({a, b}, {c, d}){}
function a([ , a]) {}
function foo([[a, b], [c, d]]) {}
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis

PREVIEWING: rtrieu/product-analytics-ui-changes