function hello1() {
console.log('hello1');
}
hello1();
//함수의 호출을 먼저
hello2();
function hello2() {
console.log("hi there");
}
함수의 호출을 먼저 한 hello2에서 오류가 발생할것 같지만 실제로는 두 함수 모두 문제 없이 작동한다.
다음 코드 구문을 보자
console.log(name);
name = 'mark';
console.log(name);
var name='yeongchan';
이 코드를 실행하면
첫번째 console.log(name)의 값이 undefined라고 되어있다.
분명 마지막 줄에 name의 값을 정의했는데도 불구하고 정의가 되어있지 않다는 오류가 나온것이 아니라 undifined라고 출력이 된다.
이번엔 let을 이용한 구문이다.
console.log(name);
name='mark';
console.log(name);
let name;
같은 방식으로 코딩을 했는데 이번엔 오류가 나타난다.
왜그럴까?