Skip to content

Commit 2e93946

Browse files
iliakanViolet-Bora-Lee
authored andcommitted
minor fixes
1 parent cb331bc commit 2e93946

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,37 @@ On the other hand, it's independently called every time when `text` is missing.
225225

226226
```
227227
228+
````smart header="Default parameters in old JavaScript code"
229+
Several years ago, JavaScript didn't support the syntax for default parameters.
230+
231+
So people used some other ways to specify default values, that you meet in old scripts.
232+
233+
For example, an explicit check for `undefined`:
234+
235+
```js
236+
function showMessage(from, text) {
237+
*!*
238+
if (text === undefined) {
239+
text = 'no text given';
240+
}
241+
*/!*
242+
243+
alert( from + ": " + text );
244+
}
245+
```
246+
247+
...Or using the `||` operator:
248+
249+
```js
250+
function showMessage(from, text) {
251+
// If the value of text is falsy, assign the default value
252+
text = text || 'no text given';
253+
...
254+
}
255+
```
256+
````
257+
258+
228259
### 매개변수 기본값을 설정할 수 있는 또 다른 방법
229260
230261
가끔은 함수 선언부에서 매개변수 기본값을 설정하는 것 대신 함수가 실행되는 도중에 기본값을 설정하는 게 논리에 맞는 경우가 생기기도 합니다. [영문 변경] Sometimes it makes sense to assign default values for parameters not in the function declaration, but at a later stage.

0 commit comments

Comments
 (0)