본문 바로가기

개발 일기

[Javascript] const에 함수를 할당하니까 갑자기 argument를 받을 수 있게 되었다,,, 띠용 / parameter와 argument의 차이

놀라움을 서술하기 이전에 argument와 parameter가 뭐가 정확히 다른 건지 모르겠어서 그것부터 잡고 가려고 합니다,,,

https://stackoverflow.com/questions/156767/whats-the-difference-between-an-argument-and-a-parameter

 

What's the difference between an argument and a parameter?

When verbally talking about methods, I'm never sure whether to use the word argument or parameter or something else. Either way the other people know what I mean, but what's correct, and what's the

stackoverflow.com

바로 스택오버플로우 들어갔는데 무려 [현직 프로그래머]도 헷갈리신다는 글을 보고 내 머리가 나쁜 게 아님을 깨달았다... 답변을 읽어 보니!

  • Parameter is the variable in the declaration of the function.
  • Argument is the actual value of this variable that gets passed to the function.

파라미터는 placeholder의 기능을 하는 variable이라고 이해를 하면 되고(함수를 선언할 때 쓰이는) argument는 정말 함수가 실사용될 때 실제로 입력되는 값이라구 한당ㅎㅎ 완벽 이해!! 하지만 또 논의가 있어서 가져왔는데...

 

The general consensus seems to be that it's OK to use these terms interchangeably in a team environment. Except perhaps when you're defining the precise terminology; then you can also use "formal argument/parameter" and "actual argument/parameter" to disambiguate.

 

그렇다구 한다ㅋㅋㅋㅋ parameter든 argument이든 협업 환경에서 딱히 엄격하게 구분해서 부르지는 않는 것 같당! 그래도 알고 있어서 손해볼 건 없으니 이런 건 근본부터 정확하게 알고 있어야 한다.

 

 암튼... 글을 쓰게 된 이유는

 

function을 variable에 할당하니 variable이 argument를 받아들일 수 있게 된 것에 충격을 받아서였다... 넘넘 신기해... 

const plantNeedsWater = function(day) {
  if(day === 'Wednesday') {
    return true;
  } else {
    return false;
  };
};

console.log(plantNeedsWater('Tuesday'));

plantNeedsWater같은 경우에는 함수가 할당되지 않고 그냥 변수로 남았으면 argument를 받을 수 없었을 텐데 함수가 할당되니 argument를 받아서 뭔가 return을 하고 있다!!!!! 넘 신기해!!!!! 하 너무 재밌다............................