Skip to content

Commit faaa8f1

Browse files
authored
Merge pull request #95 from javascript-tutorial/sync-291b5c05
Sync with upstream @ 291b5c0
2 parents 5afd223 + 98b9e51 commit faaa8f1

38 files changed

Lines changed: 156 additions & 188 deletions

File tree

1-js/02-first-steps/07-type-conversions/article.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ alert(typeof value); // string
3333

3434
Η μετατροπή συμβολοσειρών είναι αρκετά προφανής. Η `false` γίνεται `"false"`, η `null` γίνεται `"null"`, κλπ.
3535

36-
## Αριθμητική μετατροπή
36+
## Αριθμητική μετατροπή
3737

3838
Η μετατροπή αριθμών γίνεται αυτόματα σε Μαθηματικές συναρτήσεις και εκφράσεις.
3939

@@ -84,7 +84,6 @@ alert(Number(false)); // 0
8484

8585
Παρακαλώ προσέξτε ότι οι τιμές `null` και `undefined` συμπεριφέρονται διαφορετικά εδώ: η `null` γίνεται 0 (μηδέν), ενώ η `undefined` γίνεται `NaN`.
8686

87-
8887
````smart header="Ο τελεστής '+' συνενώνει συμβολοσειρές"
8988
Σχεδόν όλες οι Μαθηματικές πράξεις μετατρέπουν τιμές σε αριθμούς. Μια ξεχωριστή εξαίρεση είναι ο τελεστής `+`. Έαν μία από τις προστιθέμενες τιμές είναι μια συμβολοσειρά, τότε και η άλλη μετατρέπεται σε συμβολοσειρά.
9089

1-js/02-first-steps/08-operators/article.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ alert( 4 ** (1/2) ); // 2 (η ισχύς του 1/2 είναι η ίδια με
7373
alert( 8 ** (1/3) ); // 2 (η ισχύς του 1/3 είναι η ίδια με μια τετραγωνική ρίζα)
7474
```
7575

76-
7776
## Συνδυασμός συμβολοσειράς με δυαδικό +
7877

7978
Ας συναντήσουμε τις δυνατότητες των τελεστών JavaScript που είναι πέρα από τη σχολική αριθμητική.
@@ -109,7 +108,6 @@ alert(2 + 2 + '1' ); // "41" and not "221"
109108

110109
Το δυαδικό `+` είναι ο μόνος τελεστής που υποστηρίζει συμβολοσειρές τόσο μακριά. Άλλοι αριθμητικοί τελεστές λειτουργούν μόνο με αριθμούς και μετατρέπουν πάντα τους τελεστές τους σε αριθμούς.
111110

112-
113111
Εδώ είναι το παράδειγμα για αφαίρεση και διαίρεση:
114112

115113
```js run
@@ -200,19 +198,12 @@ alert( +apples + +oranges ); // 5
200198
| 2 | assignment | `=` |
201199
| ... | ... | ... |
202200

203-
<<<<<<< HEAD
204201
Όπως μπορούμε να δούμε, το "unary plus" έχει προτεραιότητα `17` που είναι υψηλότερη από το `13` της "προσθήκης" (δυαδικό συν). Γι 'αυτό, στην έκφραση `"+apples + +oranges"`, τα unary plus λειτουργούν πριν από την πρόσθεση.
205-
=======
206-
As we can see, the "unary plus" has a priority of `15` which is higher than the `12` of "addition" (binary plus). That's why, in the expression `"+apples + +oranges"`, unary pluses work before the addition.
207-
>>>>>>> 2cca9a9d09fdd45819832294225aa3721fa5a2d4
208202
209203
## Ανάθεση
210204
211-
<<<<<<< HEAD
205+
212206
Ας σημειώσουμε ότι μια ανάθεση `=` είναι επίσης τελεστής. Παρατίθεται στον πίνακα προτεραιότητας με την πολύ χαμηλή προτεραιότητα του `3`.
213-
=======
214-
Let's note that an assignment `=` is also an operator. It is listed in the precedence table with the very low priority of `2`.
215-
>>>>>>> 2cca9a9d09fdd45819832294225aa3721fa5a2d4
216207
217208
Γι 'αυτό, όταν εκχωρούμε μια μεταβλητή, όπως `x = 2 * 2 + 1`, οι υπολογισμοί γίνονται πρώτα και στη συνέχεια αξιολογείται το `=`, αποθηκεύοντας το αποτέλεσμα στο `x`.
218209

@@ -436,10 +427,8 @@ counter++;
436427
- RIGHT SHIFT ( `>>` )
437428
- ZERO-FILL RIGHT SHIFT ( `>>>` )
438429
439-
440430
Αυτοί οι τελεστές χρησιμοποιούνται πολύ σπάνια όταν έχουμε να κάνουμε με αριθμούς στο πολύ χαμηλότερο (bitwise) επίπεδο. Δεν θα χρειαζόμαστε αυτούς τους τελεστές σύντομα, καθώς η ανάπτυξη ιστού τους χρησιμοποιεί ελάχιστα, αλλά σε ορισμένες ειδικές περιοχές, όπως η κρυπτογραφία, είναι χρήσιμες. Μπορείτε να διαβάσετε το άρθρο του [Bitwise Operators](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators) στο MDN όταν υπάρχει ανάγκη.
441431
442-
443432
## Κόμμα
444433
445434
Ο τελεστής κόμμα `,` είναι ένας από τους σπανιότερους και πιο ασυνήθιστους τελεστές. Μερικές φορές, χρησιμοποιείται για τη σύνταξη μικρότερου κώδικα, οπότε πρέπει να το γνωρίζουμε για να κατανοήσουμε τι συμβαίνει.

1-js/02-first-steps/12-nullish-coalescing-operator/article.md

Lines changed: 2 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
[recent browser="new"]
44

5-
<<<<<<< HEAD
65
Ο μηδενικός τελεστής συγχώνευσης `??` παρέχει μια σύντομη σύνταξη για την επιλογή μιας πρώτης `καθορισμένης` μεταβλητής από τη λίστα.
76

87
Το αποτέλεσμα της `a ?? b` είναι:
@@ -15,47 +14,20 @@
1514
result = (a !== null && a !== undefined) ? a : b;```
1615
1716
Εδώ είναι ένα μεγαλύτερο παράδειγμα.
18-
=======
19-
The nullish coalescing operator is written as two question marks `??`.
20-
21-
As it treats `null` and `undefined` similarly, we'll use a special term here, in this article. We'll say that an expression is "defined" when it's neither `null` nor `undefined`.
22-
23-
The result of `a ?? b` is:
24-
- if `a` is defined, then `a`,
25-
- if `a` isn't defined, then `b`.
26-
27-
In other words, `??` returns the first argument if it's not `null/undefined`. Otherwise, the second one.
28-
29-
The nullish coalescing operator isn't anything completely new. It's just a nice syntax to get the first "defined" value of the two.
30-
31-
We can rewrite `result = a ?? b` using the operators that we already know, like this:
32-
>>>>>>> 8558fa8f5cfb16ef62aa537d323e34d9bef6b4de
3317
3418
Φανταστείτε, έχουμε έναν χρήστη και υπάρχουν μεταβλητές `firstName`, `lastName` ή `nickName` για το όνομα, το επώνυμο και το ψευδώνυμό τους. Όλα αυτά μπορεί να είναι ακαθόριστα, εάν ο χρήστης αποφασίσει να μην εισαγάγει καμία τιμή.
3519
36-
<<<<<<< HEAD
3720
Θα θέλαμε να εμφανίσουμε το όνομα χρήστη: μία από αυτές τις τρεις μεταβλητές ή να δείξουμε "Anonymous" εάν δεν έχει οριστεί τίποτα.
3821
3922
Ας χρησιμοποιήσουμε τον τελεστή `??` για να επιλέξουμε τον πρώτο καθορισμένο:
40-
=======
41-
Now it should be absolutely clear what `??` does. Let's see where it helps.
42-
43-
The common use case for `??` is to provide a default value for a potentially undefined variable.
44-
45-
For example, here we show `user` if defined, otherwise `Anonymous`:
46-
>>>>>>> 8558fa8f5cfb16ef62aa537d323e34d9bef6b4de
4723
4824
```js run
4925
let user;
5026

5127
alert(user ?? "Anonymous"); // Anonymous (user not defined)
5228
```
5329
54-
<<<<<<< HEAD
5530
Φυσικά, εάν ο `user` είχε κάποια τιμή εκτός από το `null/undefined`, τότε θα το δούμε:
56-
=======
57-
Here's the example with `user` assigned to a name:
58-
>>>>>>> 8558fa8f5cfb16ef62aa537d323e34d9bef6b4de
5931
6032
```js run
6133
let user = "John";
@@ -65,15 +37,9 @@ alert(user ?? "Anonymous"); // John (user defined)
6537
6638
Μπορούμε επίσης να χρησιμοποιήσουμε μια ακολουθία του `??` για να επιλέξουμε την πρώτη τιμή από μια λίστα που δεν είναι `null/undefined`.
6739
68-
<<<<<<< HEAD
6940
Ας υποθέσουμε ότι έχουμε δεδομένα του χρήστη σε μεταβλητές `firstName`, `lastName` ή `nickName`. Όλα αυτά μπορεί να είναι undefined, εάν ο χρήστης αποφασίσει να μην εισαγάγει μια τιμή.
7041
7142
Θα θέλαμε να εμφανίσουμε το όνομα χρήστη χρησιμοποιώντας μία από αυτές τις μεταβλητές ή να δείξουμε "Anonymous" εάν όλες είναι undefined.
72-
=======
73-
Let's say we have a user's data in variables `firstName`, `lastName` or `nickName`. All of them may be not defined, if the user decided not to enter a value.
74-
75-
We'd like to display the user name using one of these variables, or show "Anonymous" if all of them aren't defined.
76-
>>>>>>> 8558fa8f5cfb16ef62aa537d323e34d9bef6b4de
7743
7844
Ας χρησιμοποιήσουμε τον τελεστή `??` για αυτό:
7945
@@ -111,17 +77,7 @@ alert(firstName || lastName || nickName || "Anonymous"); // Supercoder
11177
*/!*
11278
```
11379
114-
<<<<<<< HEAD
11580
Αυτό ορίζει το `height` σε `100` εάν δεν έχει οριστεί.
116-
=======
117-
Historically, the OR `||` operator was there first. It exists since the beginning of JavaScript, so developers were using it for such purposes for a long time.
118-
119-
On the other hand, the nullish coalescing operator `??` was added to JavaScript only recently, and the reason for that was that people weren't quite happy with `||`.
120-
121-
The important difference between them is that:
122-
- `||` returns the first *truthy* value.
123-
- `??` returns the first *defined* value.
124-
>>>>>>> 8558fa8f5cfb16ef62aa537d323e34d9bef6b4de
12581
12682
Ας συκγρίνουμε το `||`:
12783
@@ -132,37 +88,18 @@ alert(height || 100); // 100
13288
alert(height ?? 100); // 0
13389
```
13490
135-
<<<<<<< HEAD
13691
Εδώ, `height || 100` αντιμετωπίζει το μηδέν ύψος ως μη ορισμένο, όπως το `null`, το `undefined` ή οποιαδήποτε άλλη τιμή falsy.
13792
Έτσι το αποτέλεσμα είναι `100`.
13893
Το `height ?? 100` επιστρέφει το `100` μόνο εάν το `height` είναι `null` ή `undefined`. Έτσι, το `alert` δείχνει την τιμή ύψους `0` "ως έχει".
13994
14095
Ποια συμπεριφορά είναι καλύτερη εξαρτάται από μια συγκεκριμένη περίπτωση χρήσης. Όταν το μηδέν ύψος είναι μια έγκυρη τιμή, τότε το `??` είναι προτιμότερο.
14196
14297
## Προτεραιότητα
143-
=======
144-
- The `height || 100` checks `height` for being a falsy value, and it's `0`, falsy indeed.
145-
- so the result of `||` is the second argument, `100`.
146-
- The `height ?? 100` checks `height` for being `null/undefined`, and it's not,
147-
- so the result is `height` "as is", that is `0`.
148-
149-
In practice, the zero height is often a valid value, that shouldn't be replaced with the default. So `??` does just the right thing.
150-
>>>>>>> 8558fa8f5cfb16ef62aa537d323e34d9bef6b4de
15198
15299
Η προτεραιότητα του τελεστή `??` είναι μάλλον χαμηλή: `5` στο
153100
[πίνακα MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#Table).
154101
155-
<<<<<<< HEAD
156-
<<<<<<< HEAD
157102
Για αυτό το `??` αξιολογείται μετά τις υπόλοιπες λειτουργίες, αλλά πριν από το `=` και το `?`.
158-
=======
159-
The precedence of the `??` operator is about the same as `||`, just a bit lower. It equals `5` in the [MDN table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#Table), while `||` is `6`.
160-
=======
161-
The precedence of the `??` operator is the same as `||`. They both equal `4` in the [MDN table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#Table).
162-
>>>>>>> 2cca9a9d09fdd45819832294225aa3721fa5a2d4
163-
164-
That means that, just like `||`, the nullish coalescing operator `??` is evaluated before `=` and `?`, but after most other operations, such as `+`, `*`.
165-
>>>>>>> 8558fa8f5cfb16ef62aa537d323e34d9bef6b4de
166103
167104
Εάν χρεαστούμε να επιλέξουμε μια τιμή με `??` σε μια σύνθετη έκφραση, τότε να λαμβάνεται υπ όψιν να προσθέσετε παρενθέσεις:
168105
@@ -193,7 +130,7 @@ let area = height ?? (100 * width) ?? 50;
193130
// without parentheses
194131
let area = height ?? 100 * width ?? 50;
195132

196-
// ...works the same as this (probably not what we want):
133+
// ...works this way (not what we want):
197134
let area = height ?? (100 * width) ?? 50;
198135
```
199136
@@ -204,13 +141,7 @@ let x = 1 && 2 ?? 3; // Syntax error
204141
```
205142
Ο περιορισμός είναι σίγουρα συζητήσιμος, αλλά προστέθηκε στις προδιαγραφές γλώσσας με σκοπό να αποφευχθούν λάθη προγραμματισμού, καθώς οι άνθρωποι αρχίζουν να αλλάζουν σε `??` από `||`.
206143
207-
<<<<<<< HEAD
208144
Χρησιμοποιήστε ρητές παρενθέσεις για να το επιλύσετε:
209-
=======
210-
The limitation is surely debatable, it was added to the language specification with the purpose to avoid programming mistakes, when people start to switch from `||` to `??`.
211-
212-
Use explicit parentheses to work around it:
213-
>>>>>>> 8558fa8f5cfb16ef62aa537d323e34d9bef6b4de
214145
215146
```js run
216147
*!*
@@ -233,4 +164,4 @@ alert(x); // 2
233164
```
234165
235166
- Ο τελεστής `??` έχει πολύ χαμηλή προτεραιότητα, λίγο υψηλότερος από το `?` και το `=`.
236-
- Απαγορεύεται η χρήση του με `||`" ή `&&` χωρίς ρητές παρενθέσεις.
167+
- Απαγορεύεται η χρήση του με `||`" ή `&&` χωρίς ρητές παρενθέσεις.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
No difference.
1+
No difference!
2+
3+
In both cases, `return confirm('Did parents allow you?')` executes exactly when the `if` condition is falsy.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ showMessage(from, "Hello"); // *Ann*: Hello
170170
alert( from ); // Ann
171171
```
172172
173-
174173
## Προκαθορισμένες τιμές
175174
176175
Εάν μια παράμετρος δεν παρέχεται, τότε η τιμή της γίνεται `undefined`.

1-js/02-first-steps/16-function-expressions/article.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ First, the syntax: how to differentiate between them in the code.
194194
return a + b;
195195
}
196196
```
197-
- *Function Expression:* a function, created inside an expression or inside another syntax construct. Here, the function is created at the right side of the "assignment expression" `=`:
197+
- *Function Expression:* a function, created inside an expression or inside another syntax construct. Here, the function is created on the right side of the "assignment expression" `=`:
198198

199199
```js
200200
// Function Expression
@@ -291,7 +291,7 @@ if (age < 18) {
291291
welcome(); // \ (runs)
292292
*/!*
293293
// |
294-
function welcome() { // |
294+
function welcome() { // |
295295
alert("Hello!"); // | Function Declaration is available
296296
} // | everywhere in the block where it's declared
297297
// |
@@ -301,7 +301,7 @@ if (age < 18) {
301301

302302
} else {
303303

304-
function welcome() {
304+
function welcome() {
305305
alert("Greetings!");
306306
}
307307
}

1-js/02-first-steps/17-arrow-functions-basics/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ For instance, to dynamically create a function:
6464
let age = prompt("What is your age?", 18);
6565
6666
let welcome = (age < 18) ?
67-
() => alert('Hello') :
67+
() => alert('Hello!') :
6868
() => alert("Greetings!");
6969
7070
welcome();

1-js/02-first-steps/18-javascript-specials/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ We covered three ways to create a function in JavaScript:
256256
3. Arrow functions:
257257
258258
```js
259-
// expression at the right side
259+
// expression on the right side
260260
let sum = (a, b) => a + b;
261261
262262
// or multi-line syntax with { ... }, need return here:

1-js/04-object-basics/01-object/article.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ The resulting `user` object can be imagined as a cabinet with two signed files l
4444

4545
![user object](object-user.svg)
4646

47-
We can add, remove and read files from it any time.
47+
We can add, remove and read files from it at any time.
4848

4949
Property values are accessible using the dot notation:
5050

@@ -62,7 +62,7 @@ user.isAdmin = true;
6262

6363
![user object 2](object-user-isadmin.svg)
6464

65-
To remove a property, we can use `delete` operator:
65+
To remove a property, we can use the `delete` operator:
6666

6767
```js
6868
delete user.age;
@@ -201,13 +201,13 @@ let bag = {
201201
};
202202
```
203203

204-
Square brackets are much more powerful than the dot notation. They allow any property names and variables. But they are also more cumbersome to write.
204+
Square brackets are much more powerful than dot notation. They allow any property names and variables. But they are also more cumbersome to write.
205205

206206
So most of the time, when property names are known and simple, the dot is used. And if we need something more complex, then we switch to square brackets.
207207

208208
## Property value shorthand
209209

210-
In real code we often use existing variables as values for property names.
210+
In real code, we often use existing variables as values for property names.
211211

212212
For instance:
213213

@@ -252,7 +252,7 @@ let user = {
252252

253253
## Property names limitations
254254

255-
As we already know, a variable cannot have a name equal to one of language-reserved words like "for", "let", "return" etc.
255+
As we already know, a variable cannot have a name equal to one of the language-reserved words like "for", "let", "return" etc.
256256

257257
But for an object property, there's no such restriction:
258258

@@ -325,7 +325,7 @@ alert( "blabla" in user ); // false, user.blabla doesn't exist
325325

326326
Please note that on the left side of `in` there must be a *property name*. That's usually a quoted string.
327327

328-
If we omit quotes, that means a variable, it should contain the actual name to be tested. For instance:
328+
If we omit quotes, that means a variable should contain the actual name to be tested. For instance:
329329

330330
```js run
331331
let user = { age: 30 };
@@ -412,7 +412,7 @@ for (let code in codes) {
412412
*/!*
413413
```
414414
415-
The object may be used to suggest a list of options to the user. If we're making a site mainly for German audience then we probably want `49` to be the first.
415+
The object may be used to suggest a list of options to the user. If we're making a site mainly for a German audience then we probably want `49` to be the first.
416416
417417
But if we run the code, we see a totally different picture:
418418
@@ -424,9 +424,10 @@ The phone codes go in the ascending sorted order, because they are integers. So
424424
````smart header="Integer properties? What's that?"
425425
The "integer property" term here means a string that can be converted to-and-from an integer without a change.
426426
427-
So, "49" is an integer property name, because when it's transformed to an integer number and back, it's still the same. But "+49" and "1.2" are not:
427+
So, `"49"` is an integer property name, because when it's transformed to an integer number and back, it's still the same. But `"+49"` and `"1.2"` are not:
428428
429429
```js run
430+
// Number(...) explicitly converts to a number
430431
// Math.trunc is a built-in function that removes the decimal part
431432
alert( String(Math.trunc(Number("49"))) ); // "49", same, integer property
432433
alert( String(Math.trunc(Number("+49"))) ); // "49", not same "+49" ⇒ not integer property
@@ -481,7 +482,7 @@ They store properties (key-value pairs), where:
481482
482483
To access a property, we can use:
483484
- The dot notation: `obj.property`.
484-
- Square brackets notation `obj["property"]`. Square brackets allow to take the key from a variable, like `obj[varWithKey]`.
485+
- Square brackets notation `obj["property"]`. Square brackets allow taking the key from a variable, like `obj[varWithKey]`.
485486
486487
Additional operators:
487488
- To delete a property: `delete obj.prop`.

1-js/04-object-basics/04-object-methods/7-calculator/task.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ importance: 5
66

77
Create an object `calculator` with three methods:
88

9-
- `read()` prompts for two values and saves them as object properties.
9+
- `read()` prompts for two values and saves them as object properties with names `a` and `b` respectively.
1010
- `sum()` returns the sum of saved values.
1111
- `mul()` multiplies saved values and returns the result.
1212

@@ -21,4 +21,3 @@ alert( calculator.mul() );
2121
```
2222

2323
[demo]
24-

0 commit comments

Comments
 (0)