<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
<script type="text/javascript">
var a = 10, b = 20, c;
console.log(c); // undefined - 초기값을 부여하지 않는 경우
// c = a + x; // ReferenceError 예외 발생
c = a + b;
console.log(c);
</script>
</head>
<body>
<h3>자바스크립트-변수 선언</h3>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
<script type="text/javascript">
function sub() {
// console.log(a); // 에러 : ReferenceError
console.log(x); // undefined. 자바스크립트는 나중에 선언한 변수를 참조 할 수 있다.
var x = 3;
console.log(x); // 3
/*
// 위는 아래와 동일
var x;
console.log(x);
x = 3;
console.log(x);
*/
}
sub();
</script>
</head>
<body>
<h3>변수-호이스팅(hoisting)</h3>
<p>
호이스트는 변수의 정의가 그 범위에 따라 선언과 할당으로 분리되는 것을 의미
</p>
</body>
</html>