You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A function gets outer variables as they are now, it uses the most recent values.
3
+
함수는 외부 변수의 지금 값 즉, 가장 최근의 값을 사용합니다.
4
4
5
-
Old variable values are not saved anywhere. When a function wants a variable, it takes the current value from its own Lexical Environment or the outer one.
5
+
이전 변수의 값은 어디에도 저장되지 않습니다. 함수가 변수를 찾을 때는 해당 함수의 렉시컬 환경 또는 외부 렉시컬 환경에서 현재 값을 가져옵니다.
Copy file name to clipboardExpand all lines: 1-js/06-advanced-functions/03-closure/1-closure-latest-changes/task.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,9 @@ importance: 5
2
2
3
3
---
4
4
5
-
# Does a function pickup latest changes?
5
+
# 함수가 최신 변경사항을 반영할까요??
6
6
7
-
The function sayHi uses an external variable name. When the function runs, which value is it going to use?
7
+
함수 sayHi는 외부 변수 name을 사용합니다. 함수가 실행될 때 어떤 값을 사용할까요?
8
8
9
9
```js
10
10
let name ="John";
@@ -15,9 +15,9 @@ function sayHi() {
15
15
16
16
name ="Pete";
17
17
18
-
sayHi(); //what will it show: "John" or "Pete"?
18
+
sayHi(); //뭐가 나올까요?: "John" 아니면 "Pete"?
19
19
```
20
20
21
-
Such situations are common both in browser and server-side development. A function may be scheduled to execute later than it is created, for instance after a user action or a network request.
21
+
이런 상황은 브라우저와 서버 개발 모두에서 흔하게 발생합니다. 함수는 사용자 작업이나 네트워크 요청 이후 등 생성된 것보다 나중에 실행되도록 예약될 수 있습니다.
22
22
23
-
So, the question is: does it pick up the latest changes?
The `work()`function in the code below gets `name`from the place of its origin through the outer lexical environment reference:
3
+
아래 코드의 `work()`함수는 from 만들어진 곳의 외부 렉시컬 변수 참조를 통해 `name`을 가져옵니다.
4
4
5
5

6
6
7
-
So, the result is `"Pete"` here.
7
+
그래서 결과는 `"Pete"`입니다.
8
8
9
-
But if there were no `let name` in `makeWorker()`, then the search would go outside and take the global variable as we can see from the chain above. In that case the result would be `"John"`.
9
+
그런데 만약 `makeWorker()`에 `let name`가 없으면 위의 연결에서 보이는 것처럼 외부를 검색하게 되고 전역 변수를 가져옵니다. 그러면 결과는 `"John"`이 됩니다.
In this example we can observe the peculiar difference between a "non-existing" and "uninitialized" variable.
18
+
이 예제에서는 "존재하지 않는" 변수와 "초기화되지 않은" 변수의 특이한 차이를 관찰할 수 있습니다.
19
19
20
-
As you may have read in the article [](info:closure), a variable starts in the "uninitialized" state from the moment when the execution enters a code block (or a function). And it stays uninitalized until the corresponding `let` statement.
20
+
[](info:closure)에서 읽은 것처럼 실행이 코드 블록(또는 함수)에 들어가는 순간부터 변수는 "초기화되지 않은' 상태에서 시작합니다. 그리고 해당 `let` 문이 실행될 때까지 초기화되지 않은 상태로 남아 있습니다.
21
21
22
-
In other words, a variable technically exists, but can't be used before `let`.
22
+
즉, 기술적으로 변수는 존재하지만 `let` 전에 사용할 수 없습니다.
23
23
24
-
The code above demonstrates it.
24
+
위의 코드는 이를 잘 보여줍니다.
25
25
26
26
```js
27
27
functionfunc() {
28
28
*!*
29
-
//the local variable x is known to the engine from the beginning of the function,
30
-
//but "unitialized" (unusable) until let ("dead zone")
31
-
//hence the error
29
+
//로컬 변수 x는 함수가 시작될 때부터 엔진이 알고 있지만
30
+
//let 문이 실행될 때까지 "초기화되지 않은" 상태입니다 ("dead zone").
31
+
//따라서 에러가 발생합니다.
32
32
*/!*
33
33
34
34
console.log(x); // ReferenceError: Cannot access 'x' before initialization
@@ -37,4 +37,4 @@ function func() {
37
37
}
38
38
```
39
39
40
-
This zone of temporary unusability of a variable (from the beginning of the code block till `let`) is sometimes called the "dead zone".
40
+
이 변수의 일시적 사용 불가능 구역 (코드 블록의 시작부터 `let`이 나올 때까지) "dead zone"이라 불리곤 합니다.
0 commit comments