forked from easysIT/doit_HTML-CSS-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscope.html
More file actions
24 lines (24 loc) · 737 Bytes
/
scope.html
File metadata and controls
24 lines (24 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>변수 적용 범위(scope)</title>
</head>
<body>
<script>
function addNumber(a, b) {
var sum = a + b; // 지역 변수
times_10 = sum * 10; // 전역 변수
if (a != 0 && b != 0) {
let result = a * b; // 블록 변수
// document.write("블록 변수 result : " + result + "<br>");
}
// document.write("지역 변수 sum : " + sum + "<br>");
return sum;
}
var add = addNumber(10, 20);
// document.write("전역 변수 times_10 : " + times_10 + "<br>");
</script>
</body>
</html>