JS 함수표현식

tpids·2024년 6월 9일

JS

목록 보기
22/40

함수표현식

  • 익명함수를 사용해 변수에 할당하여 사용하는 함수로 호이스팅이 발생하지 않는다.

    const func = function(매개변수, ...) {
    // 실행문장
    return 반환할 데이터;
    }

  • 함수 표현식은 const 나 let 변수에 할당하기 때문에 함수 호이스팅이 발생하지 않는다. 반드시, 초기화된 후 함수 호출 가능!
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 함수표현식
        // 익명함수를 사용해 변수에 할당한다.
        const func = function() {
            console.log('함수표현식 실행!');
        }

        func()

        let addNumber = function(num1, num2) {
            console.log(`${num1}${num2}의 더한 결과: ${num1 + num2}`);
        }

        addNumber(7,7)
    </script>
</body>
</html>
profile
개발자

0개의 댓글