Skip to content

Commit 5930fc9

Browse files
boyeonihnViolet-Bora-Lee
authored andcommitted
fix: [오번역수정] Part 1 - 2.15 [함수] 매개변수 설명 수정 (#1444)
영문 article.md에 대한 커밋을 cherry-pick를 하다가 매개변수 및 매개변수 기본값에 대한 설명이 추가되었음을 확인하고 번역 누락을 수정하기 위해 커밋 생성.
1 parent f090abc commit 5930fc9

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

Diff for: 1-js/02-first-steps/15-function-basics/article.md

+31-30
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function showMessage() {
2424

2525
```js
2626
function name(parameter1, parameter2, ... parameterN) {
27-
...함수 본문... [영문 번경]// body
27+
// 함수 본문
2828
}
2929
```
3030

@@ -137,12 +137,12 @@ alert( userName ); // 함수는 외부 변수에 접근하지 않습니다. 따
137137

138138
## 매개변수
139139

140-
매개변수(parameter)를 이용하면 임의의 데이터를 함수 안에 전달할 수 있습니다. 매개변수는 *인수(argument)* 라고 불리기도 합니다(매개변수와 인수는 엄밀히 같진 않지만, 튜토리얼 원문을 토대로 번역하였습니다 - 옮긴이). // [영어 원문 변경] We can pass arbitrary data to functions using parameters.
140+
매개변수(parameter)를 이용하면 임의의 데이터를 함수 안에 전달할 수 있습니다. 매개변수는 *인자(parameter)* 라고 불리기도 합니다.
141141

142142
아래 예시에서 함수 showMessage는 매개변수 `from``text`를 가집니다.
143143

144144
```js run
145-
function showMessage(*!*from, text*/!*) { // 인수: from, text [영어 원문 변경: parameters: from, text]
145+
function showMessage(*!*from, text*/!*) { // 인자: from, text
146146
alert(from + ': ' + text);
147147
}
148148

@@ -172,30 +172,30 @@ showMessage(from, "Hello"); // *Ann*: Hello
172172
alert( from ); // Ann
173173
```
174174
175-
When a value is passed as a function parameter, it's also called an *argument*.
175+
함수의 매개변수에 전달된 값을 *인수(argument)*라고 부르기도 합니다.
176176
177-
In other words, to put these terms straight:
177+
더 정확한 이해를 돕기 위해 용어를 다시 한번 정리해볼까요?
178178
179-
- A parameter is the variable listed inside the parentheses in the function declaration (it's a declaration time term).
180-
- An argument is the value that is passed to the function when it is called (it's a call time term).
179+
- 매개변수는 함수 선언 방식 괄호 사이에 있는 변수입니다(선언 시 쓰이는 용어).
180+
- 인수는 함수를 호출할 때 매개변수에 전달되는 값입니다(호출 시 쓰이는 용어).
181181
182-
We declare functions listing their parameters, then call them passing arguments.
182+
즉, 함수 선언 시 매개변수를 나열하게 되고, 함수를 호출할 땐 인수를 전달해 호출합니다.
183183
184-
In the example above, one might say: "the function `showMessage` is declared with two parameters, then called with two arguments: `from` and `"Hello"`".
184+
위 예에서 함수 `showMessage`는 `from`과 `text`라는 두 매개변수를 사용해 선언되었고, 그 후 호출 시엔 `from`, `Hello`라는 두 인수를 사용해 호출되었습니다.
185185
186186
## 기본값
187187
188-
매개변수에 값을 전달하지 않으면 그 값은 `undefined`가 됩니다. [영어 원문 변경사항] If a function is called, but an argument is not provided, then the corresponding value becomes `undefined`.
188+
함수 호출 시 매개변수에 인수를 전달하지 않으면 그 값은 `undefined`가 됩니다.
189189
190190
예시를 통해 이에 대해 알아봅시다. 위에서 정의한 함수 `showMessage(from, text)`는 매개변수가 2개지만, 아래와 같이 인수를 하나만 넣어서 호출할 수 있습니다.
191191
192192
```js
193193
showMessage("Ann");
194194
```
195195
196-
이렇게 코드를 작성해도 에러가 발생하지 않습니다. 두 번째 매개변수에 값을 전달하지 않았기 때문에 `text`엔 `undefiend`가 할당될 뿐입니다. 따라서 에러 없이 `"Ann: undefined"`가 출력됩니다.
196+
이렇게 코드를 작성해도 에러가 발생하지 않습니다. 두 번째 매개변수에 값을 전달하지 않았기 때문에 `text`엔 `undefined`가 할당될 뿐입니다. 따라서 에러 없이 `"Ann: undefined"`가 출력됩니다.
197197
198-
매개변수에 값을 전달하지 않아도 그 값이 `undefined`가 되지 않게 하려면 '기본값(default value)'을 설정해주면 됩니다. 매개변수 오른쪽에 `=`을 붙이고 `undefined` 대신 설정하고자 하는 기본값을 써주면 되죠. [영문 변경] We can specify the so-called "default" (to use if omitted) value for a parameter in the function declaration, using `=`:
198+
매개변수에 값을 전달하지 않아도 그 값이 `undefined`가 되지 않게 하려면 함수를 선언할 때 `=`를 사용해 '기본값(default value)'을 설정해주면 됩니다.
199199
200200
```js run
201201
function showMessage(from, *!*text = "no text given"*/!*) {
@@ -205,10 +205,11 @@ function showMessage(from, *!*text = "no text given"*/!*) {
205205
showMessage("Ann"); // Ann: no text given
206206
```
207207
208-
이젠 `text`가 값을 전달받지 못해도 `undefined`대신 기본값 `"no text given"`이 할당됩니다.
208+
이젠 `text`가 값을 전달받지 못해도 `undefined` 대신 기본값 `"no text given"`이 할당됩니다.
209209
210-
The default value also jumps in if the parameter exists, but strictly equals `undefined`, like this:
210+
매개변수에 값을 전달해도 그 값이 `undefined`와 엄격히 일치한다면 기본값이 할당됩니다.
211211
212+
예시:
212213
```js
213214
showMessage("Ann", undefined); // Ann: no text given
214215
```
@@ -225,19 +226,20 @@ function showMessage(from, text = anotherFunction()) {
225226
```smart header="매개변수 기본값 평가 시점"
226227
자바스크립트에선 함수를 호출할 때마다 매개변수 기본값을 평가합니다. 물론 해당하는 매개변수가 없을 때만 기본값을 평가하죠.
227228
228-
위 예시에선 매개변수 `text`에 값이 없는 경우 `showMessage()`를 호출할 때마다 `anotherFunction()`이 호출됩니다. [영문 변경사항:] In the example above, `anotherFunction()` isn't called at all, if the `text` parameter is provided.
229+
위 예시에선 매개변수 `text`에 값이 전달되는 경우 `anotherFunction()`은 호출되지 않습니다.
229230
230-
On the other hand, it's independently called every time when `text` is missing.
231+
반면 `text`에 값이 없는 경우 `showMessage()`를 호출할 때마다 `anotherFunction()`이 호출됩니다.
231232
232233
```
233234
234-
````smart header="Default parameters in old JavaScript code"
235-
Several years ago, JavaScript didn't support the syntax for default parameters. So people used other ways to specify them.
235+
````smart header="구식 자바스크립트에서 매개변수 기본값 설정하는 방법"
236+
몇 년 전만 해도 자바스크립트엔 매개변수 기본값 관련 구문이 없었습니다. 그래서 매개변수 기본값을 설정하려면 다른 방법을 사용해야만 했죠.
236237
237-
Nowadays, we can come across them in old scripts.
238+
요즘에도 오래된 스크립트를 보다 보면 매개변수 기본값 설정 관련 코드를 접할 수 있습니다.
238239
239-
For example, an explicit check for `undefined`:
240+
구식 코드에서는 매개변수 기본값 설정을 위해 먼저 매개변수 값이 `undefined`인지 명시적으로 확인하고, 일치하는 경우엔 기본값을 설정합니다.
240241
242+
예시:
241243
```js
242244
function showMessage(from, text) {
243245
*!*
@@ -250,12 +252,12 @@ function showMessage(from, text) {
250252
}
251253
```
252254
253-
...Or using the `||` operator:
255+
이 방법 말고도 논리 연산자 `||`를 사용해 매개변수 기본값을 설정하는 방법도 있습니다.
254256
255257
```js
256258
function showMessage(from, text) {
257-
// If the value of text is falsy, assign the default value
258-
// this assumes that text == "" is the same as no text at all
259+
// text의 값이 falsy면 기본값이 할당됨
260+
// 이 방식은 text == ""일 경우, text에 값이 전달되지 않은것과 같다고 간주합니다..
259261
text = text || 'no text given';
260262
...
261263
}
@@ -265,18 +267,17 @@ function showMessage(from, text) {
265267
266268
### 매개변수 기본값을 설정할 수 있는 또 다른 방법
267269
268-
<<<<<<< HEAD
269-
가끔은 함수 선언부에서 매개변수 기본값을 설정하는 것 대신 함수가 실행되는 도중에 기본값을 설정하는 게 논리에 맞는 경우가 생기기도 합니다. [영문 변경] Sometimes it makes sense to assign default values for parameters at a later stage after the function declaration.
270+
가끔은 함수를 선언할 때가 아닌 함수 선언 후에 매개변수 기본값을 설정하는 것이 적절한 경우도 있습니다.
270271
271-
이런 경우엔 일단 매개변수를 `undefined`와 비교하여 함수 호출 시 매개변수가 생략되었는지를 확인합니다. [영문 변경사항:] We can check if the parameter is passed during the function execution, by comparing it with `undefined`:
272+
이런 경우엔 함수를 호출할 때 매개변수를 `undefined`와 비교하여 매개변수가 전달되었는지를 확인합니다.
272273
273274
```js run
274275
function showMessage(text) {
275276
// ...
276277
277278
*!*
278-
if (text === undefined) { // [영문 변경] if the parameter is missing
279-
text = '빈 문자열';
279+
if (text === undefined) { // 매개변수가 생략되었다면
280+
text = '빈 문자열';
280281
}
281282
*/!*
282283
@@ -289,7 +290,7 @@ showMessage(); // 빈 문자열
289290
이렇게 `if`문을 쓰는 것 대신 논리 연산자 `||`를 사용할 수도 있습니다.
290291
291292
```js
292-
// 매개변수가 생략되었거나 빈 문자열("")이 넘어오면 변수에 '빈 문자열'이 할당됩니다.
293+
// 매개변수가 생략되었거나 빈 문자열("")이 넘어오면 변수에 '빈 문자열'이 할당됩니다.
293294
function showMessage(text) {
294295
text = text || '빈 문자열';
295296
...
@@ -299,7 +300,7 @@ function showMessage(text) {
299300
이 외에도 모던 자바스크립트 엔진이 지원하는 [nullish 병합 연산자(nullish coalescing operator)](info:nullish-coalescing-operator) `??`를 사용하면 `0`처럼 falsy로 평가되는 값들을 일반 값처럼 처리할 수 있어서 좋습니다.
300301
301302
```js run
302-
// 매개변수 'count'가 넘어오지 않으면 'unknown'을 출력해주는 함수 [영문 변경] // if count is undefined or null, show "unknown"
303+
// 매개변수 'count'`undefined` 또는 `null`이면 'unknown'을 출력해주는 함수
303304
function showCount(count) {
304305
alert(count ?? "unknown");
305306
}

0 commit comments

Comments
 (0)