인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

appp82290825's profile image
appp82290825

asked

JavaScript Intermediate to Advanced: Engine Core

8. Hoisting, calling from the front of the function, [Coding time]

강사님 변수이름에 get을 붙이는 이유를 알고싶습니다.

Written on

·

296

0

function book() {
    var getBook = function() {
        return "책 1";
    };
    console.log(getBook());
    function getBook() {
        return "책2";
    }
}
book();
 
이건 되는데
 
function book() {
    var a = function() {
        return "책 1";
    };
    console.log(getBook());
    function a() {
        return "책2";
    }
}
book();
 
이건 왜 안되나요??
javascript

Answer 1

1

두번째 안되는 코드에서 getBook이라는 이름을 가진 함수를 console.log로 호출 하는데 getBook이라는 함수가 없으니까 안되는겁니다. console.log(a)를 하시면 정상 작동합니다

appp82290825's profile image
appp82290825

asked

Ask a question