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
When a value is passed as a function parameter, it'salsocalledan*argument*.
176
-
177
-
Inotherwords, toputthesetermsstraight:
178
-
179
-
-Aparameteristhevariablelistedinsidetheparenthesesinthefunctiondeclaration (it's a declaration time term).
180
-
- An argument is the value that is passed to the function when it is called (it'sacalltimeterm).
181
-
182
-
We declare functions listing their parameters, then call them passing arguments.
183
-
184
-
In the example above, one might say: "the function `showMessage` is declared with two parameters, then called with two arguments: `from` and `"Hello"`".
185
-
186
-
>>>>>>> 291b5c05b99452cf8a0d32bd32426926dbcc0ce0
187
-
188
173
## Προκαθορισμένες τιμές
189
174
190
175
Εάν μια παράμετρος δεν παρέχεται, τότε η τιμή της γίνεται `undefined`.
@@ -222,43 +207,7 @@ function showMessage(from, text = anotherFunction()) {
222
207
223
208
Στο παραπάνω παράδειγμα, το `anotherFunction()` καλείται κάθε φορά που το `showMessage()` καλείται χωρίς την παράμετρο `text`.
224
209
225
-
<<<<<<<HEAD
226
210
### Εναλλακτικοί προεπιλεγμένοι παράμετροι
227
-
=======
228
-
````smartheader="Default parameters in old JavaScript code"
229
-
Severalyearsago, JavaScriptdidn't support the syntax for default parameters. So people used other ways to specify them.
230
-
231
-
Nowadays, we can come across them 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 = 'notextgiven';
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
-
// this assumes that text == "" is the same as no text at all
253
-
text = text || 'notextgiven';
254
-
...
255
-
}
256
-
```
257
-
````
258
-
259
-
260
-
### Alternative default parameters
261
-
>>>>>>> 291b5c05b99452cf8a0d32bd32426926dbcc0ce0
262
211
263
212
Μερικές φορές έχει νόημα να ορίσετε προεπιλεγμένες τιμές για παραμέτρους όχι στη δήλωση συνάρτησης, αλλά σε μεταγενέστερο στάδιο, κατά την εκτέλεση.
0 commit comments