본문 바로가기
개발/JavaScript

[JavaScript] parameter vs argument

by coking 2023. 2. 4.

javascript에서 함수를 선언하고 사용하다 보면 parameter란 단어와 argument라는 단어를 자주 접하게 된다. 한국말로는 매개변수, 인자 등으로 불린다. 구글에도 javascript argument vs parameter라고 검색하면 정말 많은 글들이 나올 정도로 많은 사람들이 궁금해하는 주제이다. 어쩌면 사용하면서 자신도 모르게 습득해서 잘 사용하고 있을 수도 있지만 명확히 알고 사용하기 위해 정리해 보자!

 

parameter vs argument 

function example(parameter) {
  console.log(parameter); // Output = foo
}

const argument = "foo";

example(argument);

mdn 공식 예제를 보면 위 코드 예시와 같이 쉽게 나와있다.  parameter란 함수의 정의에 나열된 이름을 가르치고, argument란 함수에 전달되는 실제 값을 뜻한다. 결론적으로 parameter는 함수 호출 시 전달되는 argument에 의해 초기화된다. 

 

또한 wikipedia에 parameter 관련된 글이나 다른 외국 문서들을 보면 parameter를 formal parameter, argument를 actual parameter라고 부르는 경우도 있으며 형식 매개변수, 실제 매개변수 등으로 사용되고 있는 듯하다. 

 

 

 

https://developer.mozilla.org/en-US/docs/Glossary/Parameter

 

Parameter - MDN Web Docs Glossary: Definitions of Web-related terms | MDN

A parameter is a named variable passed into a function. Parameter variables are used to import arguments into functions.

developer.mozilla.org

https://en.wikipedia.org/wiki/Parameter_(computer_programming) 

 

Parameter (computer programming) - Wikipedia

From Wikipedia, the free encyclopedia An input provided to a function/subroutine In computer programming, a parameter or a formal argument is a special kind of variable used in a subroutine to refer to one of the pieces of data provided as input to the sub

en.wikipedia.org

https://chortle.ccsu.edu/java5/Notes/chap34A/ch34A_3.html

 

Formal and Actual Parameters

An identifier is a name used for a class, a variable, a method, or a parameter. The following definitions are useful: Note: formal parameters are bound to an actual value only as long as their method is active. When a method returns to its caller, the form

chortle.ccsu.edu

 

댓글