Skip to content

Commit c759e0c

Browse files
Dohun-choiViolet-Bora-Lee
authored andcommitted
[신규번역] part1 6.3 함수 심화학습 - 변수의 유효범위와 클로저의 과제
1 parent e8a3f4e commit c759e0c

File tree

6 files changed

+33
-33
lines changed

6 files changed

+33
-33
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
The answer is: **Pete**.
1+
정답은 **Pete**입니다.
22

3-
A function gets outer variables as they are now, it uses the most recent values.
3+
함수는 외부 변수의 지금 값 즉, 가장 최근의 값을 사용합니다.
44

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+
이전 변수의 값은 어디에도 저장되지 않습니다. 함수가 변수를 찾을 때는 해당 함수의 렉시컬 환경 또는 외부 렉시컬 환경에서 현재 값을 가져옵니다.

1-js/06-advanced-functions/03-closure/1-closure-latest-changes/task.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 5
22

33
---
44

5-
# Does a function pickup latest changes?
5+
# 함수가 최신 변경사항을 반영할까요??
66

7-
The function sayHi uses an external variable name. When the function runs, which value is it going to use?
7+
함수 sayHi는 외부 변수 name을 사용합니다. 함수가 실행될 때 어떤 값을 사용할까요?
88

99
```js
1010
let name = "John";
@@ -15,9 +15,9 @@ function sayHi() {
1515

1616
name = "Pete";
1717

18-
sayHi(); // what will it show: "John" or "Pete"?
18+
sayHi(); // 뭐가 나올까요?: "John" 아니면 "Pete"?
1919
```
2020

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+
이런 상황은 브라우저와 서버 개발 모두에서 흔하게 발생합니다. 함수는 사용자 작업이나 네트워크 요청 이후 등 생성된 것보다 나중에 실행되도록 예약될 수 있습니다.
2222

23-
So, the question is: does it pick up the latest changes?
23+
그래서, 이 함수가 최신 변경사항을 반영할까요?
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
The answer is: **Pete**.
1+
정답은 **Pete**입니다.
22

3-
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`을 가져옵니다.
44

55
![](lexenv-nested-work.svg)
66

7-
So, the result is `"Pete"` here.
7+
그래서 결과는 `"Pete"`입니다.
88

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"`이 됩니다.

1-js/06-advanced-functions/03-closure/2-closure-variable-access/task.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@ importance: 5
22

33
---
44

5-
# Which variables are available?
5+
# 어떤 변수가 사용가능할까요?
66

7-
The function `makeWorker` below makes another function and returns it. That new function can be called from somewhere else.
7+
아래의 `makeWorker` 함수는 다른 함수를 만들고 만든 함수를 반환합니다. 반환된 새 함수는 다른 어딘가에서 호출될 수 있습니다.
88

9-
Will it have access to the outer variables from its creation place, or the invocation place, or both?
9+
새롭게 반환된 함수는 생성된 곳에서 외부 변수에 접근할까요, 아니면 호출된 위치에서 외부 변수에 접근할까요? 아니면 둘 다 일까요?
1010

1111
```js
1212
function makeWorker() {
1313
let name = "Pete";
1414

15-
return function() {
15+
return function () {
1616
alert(name);
1717
};
1818
}
1919

2020
let name = "John";
2121

22-
// create a function
22+
// 함수를 만듭니다.
2323
let work = makeWorker();
2424

25-
// call it
26-
work(); // what will it show?
25+
// 함수를 호출합니다.
26+
work(); // 무엇이 나올까요?
2727
```
2828

29-
Which value it will show? "Pete" or "John"?
29+
어떤 값이 나타날까요? “Pete”일까요? “John”일까요?
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
The result is: **error**.
1+
결과는 에러입니다.
22

3-
Try running it:
3+
실행해 보세요:
44

55
```js run
66
let x = 1;
@@ -15,20 +15,20 @@ function func() {
1515
func();
1616
```
1717

18-
In this example we can observe the peculiar difference between a "non-existing" and "uninitialized" variable.
18+
이 예제에서는 "존재하지 않는" 변수와 "초기화되지 않은" 변수의 특이한 차이를 관찰할 수 있습니다.
1919

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` 문이 실행될 때까지 초기화되지 않은 상태로 남아 있습니다.
2121

22-
In other words, a variable technically exists, but can't be used before `let`.
22+
즉, 기술적으로 변수는 존재하지만 `let` 전에 사용할 수 없습니다.
2323

24-
The code above demonstrates it.
24+
위의 코드는 이를 잘 보여줍니다.
2525

2626
```js
2727
function func() {
2828
*!*
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+
// 따라서 에러가 발생합니다.
3232
*/!*
3333

3434
console.log(x); // ReferenceError: Cannot access 'x' before initialization
@@ -37,4 +37,4 @@ function func() {
3737
}
3838
```
3939

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"이라 불리곤 합니다.

1-js/06-advanced-functions/03-closure/7-let-scope/task.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 4
22

33
---
44

5-
# Is variable visible?
5+
# 변수가 보일까요?
66

7-
What will be the result of this code?
7+
다음 코드의 결과는 무엇일까요?
88

99
```js
1010
let x = 1;
@@ -18,4 +18,4 @@ function func() {
1818
func();
1919
```
2020

21-
P.S. There's a pitfall in this task. The solution is not obvious.
21+
P.S. 이 문제에는 함정이 있습니다. 해결 방법이 명확하지 않습니다.

0 commit comments

Comments
 (0)