JavaScript
JavaScript - Hoisting
dev-sh
2019. 9. 14. 15:48
In JavaScript, there is a rule for Declaration.
Every variable will be hoisted to top.
Remember! Just Declaration, Not a value
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>호이스팅 :: Hoisting</title>
<script type="text/javascript">
//1. hoisting
doSomething();
function doSomething() {
alert("not defined : "+some); //undefined
var some = "WellBeing";
alert("defined : "+some); //WellBeing
};
//2. Global Variable
var name = "James";
function showName(){
var name = "Gosling";
console.log(name);
}
console.log(name);
showName();
</script>
</head>
<body>
</body>
</html>