Javascript/함수
선언적 function 과 익명 함수를 만들어 변수에 할당
컴공 윤서혜 학습일기
2021. 1. 26. 13:49
다음과 같이 2가지 방법이 있고 출력값도 동일하게 나온다.
1. 선언적 function
// 함수의 매개변수
// 함수를 호출할 때 값을 지정
function hello2(name){
console.log('hello2', name);
}
// 함수의 리턴
// 함수를 실행하면 얻어지는 값
function hello3(name){
return `hello3 ${name}`;
}
console.log(hello3('Mark'));
console.log(hello2('Amy'));
출력값
hello3 Mark
hello2 Amy
2. 익명 함수를 만들어 변수에 할당
const hello2 = function(name){
console.log('hello2', name);
}
const hello3 = function(name){
return `hello3 ${name}`;
}
console.log(hello3('Mark'));
console.log(hello2('Amy'));
출력값
hello3 Mark
hello2 Amy