소스 코드를 기록하는 남자

JavaScript - Hoisting

JavaScript

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>

'JavaScript' 카테고리의 다른 글

JavaScript - Function Executing Process  (0) 2019.09.14
JavaScript - Global Variable  (0) 2019.09.14
JavaScript - window.onload  (0) 2019.09.14
JavaScript - Escape character, Operator  (0) 2019.09.14
JavaScript - Datatype  (0) 2019.09.14