-
parameter와 argument의 차이CS지식 모음 2023. 3. 28. 13:14
parameter와 argument는 분명히 다르다고 하는데 저는 뭐가 다른지 알지 못합니다.
자, 이번에는 GPT선생님한테 물어보았습니다.
GPT선생님은 parameter와 argument가 자바스크립트 함수에서 매우 중요한 개념이라고 하네요.
개념은 GPT선생님이 답변해준걸 보고 한번에 이해됐습니다.
parameter는 함수를 "정의 할 때" 함수의 인자를 나타내는 변수를 말합니다.
함수를 "호출하기 전"에 미리 정의되며, 함수의 인자 값을 함수 내부에서 참조하여 사용합니다.
// 예시코드 const greet = (name) => { console.log(`hello, ${name}!`); }
위 예제에서 name은 함수 greet의 parameter입니다.
argument는 함수를 "호출 할 때" 함수에 전달하는 인자를 말합니다.
함수를 "호출할 때마다 값이 달라질 수 있으며", 호출된 함수 내부에서 인자 값을 참조하여 사용합니다.
// 예시코드 greet('John')
위 예제에서 Jone은 함수 greet의 argument 입니다.
따라서 parameter와 argument는 함수에서 서로 다른 역할을 하며,
함수를 정의할 때 parameter를 선언하고,
함수를 호출할 때 argument를 전달합니다.
'CS지식 모음' 카테고리의 다른 글
HTTP에 대해 설명해주세요. (0) 2023.03.30 캐시(Cache)에 대하여 설명해주세요. (0) 2023.03.29 프레임워크와 라이브러리의 차이점을 설명해주세요. (0) 2023.03.29 Hoisting과 TDZ 대하여 (0) 2023.03.28 브라우저 렌더링 과정을 설명할 수 있나요? (2) 2023.03.27