function2 JavaScript기초(17)_함수(3) 1. 선언적 function과 익명 함수의 변수에 할당하는 표현방식의 차이 우선 아래의 코드를 살펴보자. 함수 호출을 먼저 하고 뒤에 선언적 function을 입력했다. hello(); function hello(){ console.log('hello!'); } [Running] hello! 선언을 뒤에 하고 호출을 먼저하더라도 함수 결과 값이 정상적으로 함수 호출이 된다. 그렇다면 변수에 함수를 할당한 경우는 어떤지 살펴보자. hello(); var hello = function (){ console.log('hello!'); }; [Running] hello(); ^ TypeError: hello is not a function 에러 메시지를 통해서, 먼저 호출한 hello를 함수로 인식하지 못함을 .. 2021. 10. 11. JavaScript기초(16)_함수(2) 1. const hello = function() {} : 익명적 함수를 만들어 변수에 할당 아래와 같이 함수를 변수 화하여 나타낼 수 있다. const hello = function(){ console.log('hello'); }; console.log(hello); [Running] [Function: hello] 매개변수가 있더라도 크게 다르지 않다. const hello2 = function(name){ console.log('hello', name); }; const hello3 = function(name){ return `hello3 ${name}`; }; 2021. 10. 10. 이전 1 다음