JavaScript - Global Variable
JavaScriptIn javaScript, it is different from other langauge.
Lets see the code.
after showAge function called, the variable "age" is changed to a Global Variable
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
<script type="text/javascript">
// Global Variable Declaration (3) a Global variable connected to window object
/* var myName = "James";
//
firstName = "Gosling";
//
var name;
name = "James Gosling";
console.log(myName +' '+firstName+" "+name); */
//2. A Global Variable with function
function showAge() {
age = 90;
//console.log(age);
}
showAge(); //after function called, age will be a global variable
console.log(age);
</script>
</head>
<body>
</body>
</html>
'JavaScript' 카테고리의 다른 글
JavaScript - typeof(), prompt(), String(), Number() (0) | 2019.09.14 |
---|---|
JavaScript - Function Executing Process (0) | 2019.09.14 |
JavaScript - Hoisting (0) | 2019.09.14 |
JavaScript - window.onload (0) | 2019.09.14 |
JavaScript - Escape character, Operator (0) | 2019.09.14 |