-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1_function_2.html
More file actions
51 lines (38 loc) · 1.47 KB
/
1_function_2.html
File metadata and controls
51 lines (38 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
/*
호이스팅 : 함수 선언식은 호이스팅에 영향을 받지만, 함수 표현식은 호이스팅에 영향을 받지 않는다.
함수 선언식은 코드를 구현한 위치와 관계없이 자바스크립트의 특징인 호이스팅에 따라
브라우저가 자바스크립트를 해석할 때 맨 위로 끌어 올려진다.
호이스팅 관련 오류 : Uncaught ReferenceError: Cannot access 'add2' before initialization
*/
// 선언식은 나온다.
let r = add(1,3);
console.log("처음 덧셈 결과 :" + r)
// 선언식은 나온다.
r = add(7,1);
console.log("두번째 덧셈 결과 :" + r)
// 표현식은 안나온다.
r = add2(6,7)
console.log("함수표현식 :" + r)
// 함수 선언식 : 호이스팅 영향 (o)
function add (a,b){
let k = a+b;
return k;
}
// 함수 표현식 : 호이스팅 영향 (x)
let add2 = function (a,b){
let k = a+b;
return k;
}
</script>
</body>
</html>