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
Σχεδόν όλες οι Μαθηματικές πράξεις μετατρέπουν τιμές σε αριθμούς. Μια ξεχωριστή εξαίρεση είναι ο τελεστής `+`. Έαν μία από τις προστιθέμενες τιμές είναι μια συμβολοσειρά, τότε και η άλλη μετατρέπεται σε συμβολοσειρά.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/08-operators/article.md
+1-12Lines changed: 1 addition & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,7 +73,6 @@ alert( 4 ** (1/2) ); // 2 (η ισχύς του 1/2 είναι η ίδια με
73
73
alert( 8 ** (1/3) ); // 2 (η ισχύς του 1/3 είναι η ίδια με μια τετραγωνική ρίζα)
74
74
```
75
75
76
-
77
76
## Συνδυασμός συμβολοσειράς με δυαδικό +
78
77
79
78
Ας συναντήσουμε τις δυνατότητες των τελεστών JavaScript που είναι πέρα από τη σχολική αριθμητική.
@@ -109,7 +108,6 @@ alert(2 + 2 + '1' ); // "41" and not "221"
109
108
110
109
Το δυαδικό `+` είναι ο μόνος τελεστής που υποστηρίζει συμβολοσειρές τόσο μακριά. Άλλοι αριθμητικοί τελεστές λειτουργούν μόνο με αριθμούς και μετατρέπουν πάντα τους τελεστές τους σε αριθμούς.
111
110
112
-
113
111
Εδώ είναι το παράδειγμα για αφαίρεση και διαίρεση:
Όπως μπορούμε να δούμε, το "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
208
202
209
203
## Ανάθεση
210
204
211
-
<<<<<<<HEAD
205
+
212
206
Ας σημειώσουμε ότι μια ανάθεση `=` είναι επίσης τελεστής. Παρατίθεται στον πίνακα προτεραιότητας με την πολύ χαμηλή προτεραιότητα του `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
216
207
217
208
Γι 'αυτό, όταν εκχωρούμε μια μεταβλητή, όπως `x = 2 * 2 + 1`, οι υπολογισμοί γίνονται πρώτα και στη συνέχεια αξιολογείται το `=`, αποθηκεύοντας το αποτέλεσμα στο `x`.
218
209
@@ -436,10 +427,8 @@ counter++;
436
427
- RIGHT SHIFT ( `>>` )
437
428
- ZERO-FILL RIGHT SHIFT ( `>>>` )
438
429
439
-
440
430
Αυτοί οι τελεστές χρησιμοποιούνται πολύ σπάνια όταν έχουμε να κάνουμε με αριθμούς στο πολύ χαμηλότερο (bitwise) επίπεδο. Δεν θα χρειαζόμαστε αυτούς τους τελεστές σύντομα, καθώς η ανάπτυξη ιστού τους χρησιμοποιεί ελάχιστα, αλλά σε ορισμένες ειδικές περιοχές, όπως η κρυπτογραφία, είναι χρήσιμες. Μπορείτε να διαβάσετε το άρθρο του [Bitwise Operators](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators) στο MDN όταν υπάρχει ανάγκη.
441
431
442
-
443
432
## Κόμμα
444
433
445
434
Ο τελεστής κόμμα `,` είναι ένας από τους σπανιότερους και πιο ασυνήθιστους τελεστές. Μερικές φορές, χρησιμοποιείται για τη σύνταξη μικρότερου κώδικα, οπότε πρέπει να το γνωρίζουμε για να κατανοήσουμε τι συμβαίνει.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/12-nullish-coalescing-operator/article.md
+2-71Lines changed: 2 additions & 71 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,6 @@
2
2
3
3
[recent browser="new"]
4
4
5
-
<<<<<<< HEAD
6
5
Ο μηδενικός τελεστής συγχώνευσης `??` παρέχει μια σύντομη σύνταξη για την επιλογή μιας πρώτης `καθορισμένης` μεταβλητής από τη λίστα.
7
6
8
7
Το αποτέλεσμα της `a ?? b` είναι:
@@ -15,47 +14,20 @@
15
14
result = (a !==null&& a !==undefined) ? a : b;```
16
15
17
16
Εδώ είναι ένα μεγαλύτερο παράδειγμα.
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
33
17
34
18
Φανταστείτε, έχουμε έναν χρήστη και υπάρχουν μεταβλητές `firstName`, `lastName` ή `nickName` για το όνομα, το επώνυμο και το ψευδώνυμό τους. Όλα αυτά μπορεί να είναι ακαθόριστα, εάν ο χρήστης αποφασίσει να μην εισαγάγει καμία τιμή.
35
19
36
-
<<<<<<< HEAD
37
20
Θα θέλαμε να εμφανίσουμε το όνομα χρήστη: μία από αυτές τις τρεις μεταβλητές ή να δείξουμε "Anonymous" εάν δεν έχει οριστεί τίποτα.
38
21
39
22
Ας χρησιμοποιήσουμε τον τελεστή `??` για να επιλέξουμε τον πρώτο καθορισμένο:
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
47
23
48
24
```js run
49
25
let user;
50
26
51
27
alert(user ??"Anonymous"); // Anonymous (user not defined)
52
28
```
53
29
54
-
<<<<<<< HEAD
55
30
Φυσικά, εάν ο `user` είχε κάποια τιμή εκτός από το `null/undefined`, τότε θα το δούμε:
56
-
=======
57
-
Here's the example with `user` assigned to a name:
Μπορούμε επίσης να χρησιμοποιήσουμε μια ακολουθία του `??` για να επιλέξουμε την πρώτη τιμή από μια λίστα που δεν είναι `null/undefined`.
67
39
68
-
<<<<<<< HEAD
69
40
Ας υποθέσουμε ότι έχουμε δεδομένα του χρήστη σε μεταβλητές `firstName`, `lastName` ή `nickName`. Όλα αυτά μπορεί να είναι undefined, εάν ο χρήστης αποφασίσει να μην εισαγάγει μια τιμή.
70
41
71
42
Θα θέλαμε να εμφανίσουμε το όνομα χρήστη χρησιμοποιώντας μία από αυτές τις μεταβλητές ή να δείξουμε "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.
Αυτό ορίζει το `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
125
81
126
82
Ας συκγρίνουμε το `||`:
127
83
@@ -132,37 +88,18 @@ alert(height || 100); // 100
132
88
alert(height ??100); // 0
133
89
```
134
90
135
-
<<<<<<< HEAD
136
91
Εδώ, `height ||100` αντιμετωπίζει το μηδέν ύψος ως μη ορισμένο, όπως το `null`, το `undefined` ή οποιαδήποτε άλλη τιμή falsy.
137
92
Έτσι το αποτέλεσμα είναι `100`.
138
93
Το `height ??100` επιστρέφει το `100` μόνο εάν το `height` είναι `null` ή `undefined`. Έτσι, το `alert` δείχνει την τιμή ύψους `0` "ως έχει".
139
94
140
95
Ποια συμπεριφορά είναι καλύτερη εξαρτάται από μια συγκεκριμένη περίπτωση χρήσης. Όταν το μηδέν ύψος είναι μια έγκυρη τιμή, τότε το `??` είναι προτιμότερο.
141
96
142
97
## Προτεραιότητα
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
151
98
152
99
Η προτεραιότητα του τελεστή `??` είναι μάλλον χαμηλή: `5` στο
Για αυτό το `??` αξιολογείται μετά τις υπόλοιπες λειτουργίες, αλλά πριν από το `=` και το `?`.
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
166
103
167
104
Εάν χρεαστούμε να επιλέξουμε μια τιμή με `??` σε μια σύνθετη έκφραση, τότε να λαμβάνεται υπ όψιν να προσθέσετε παρενθέσεις:
168
105
@@ -193,7 +130,7 @@ let area = height ?? (100 * width) ?? 50;
193
130
// without parentheses
194
131
let area = height ??100* width ??50;
195
132
196
-
// ...works the same as this (probably not what we want):
133
+
// ...works this way (not what we want):
197
134
let area = height ?? (100* width) ??50;
198
135
```
199
136
@@ -204,13 +141,7 @@ let x = 1 && 2 ?? 3; // Syntax error
204
141
```
205
142
Ο περιορισμός είναι σίγουρα συζητήσιμος, αλλά προστέθηκε στις προδιαγραφές γλώσσας με σκοπό να αποφευχθούν λάθη προγραμματισμού, καθώς οι άνθρωποι αρχίζουν να αλλάζουν σε `??` από `||`.
206
143
207
-
<<<<<<< HEAD
208
144
Χρησιμοποιήστε ρητές παρενθέσεις για να το επιλύσετε:
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
214
145
215
146
```js run
216
147
*!*
@@ -233,4 +164,4 @@ alert(x); // 2
233
164
```
234
165
235
166
- Ο τελεστής `??` έχει πολύ χαμηλή προτεραιότητα, λίγο υψηλότερος από το `?` και το `=`.
236
-
- Απαγορεύεται η χρήση του με `||`" ή `&&` χωρίς ρητές παρενθέσεις.
167
+
- Απαγορεύεται η χρήση του με `||`" ή `&&` χωρίς ρητές παρενθέσεις.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/16-function-expressions/article.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -194,7 +194,7 @@ First, the syntax: how to differentiate between them in the code.
194
194
return a + b;
195
195
}
196
196
```
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" `=`:
198
198
199
199
```js
200
200
// Function Expression
@@ -291,7 +291,7 @@ if (age < 18) {
291
291
welcome(); // \ (runs)
292
292
*/!*
293
293
// |
294
-
functionwelcome() { // |
294
+
functionwelcome() { // |
295
295
alert("Hello!"); // | Function Declaration is available
296
296
} // | everywhere in the block where it's declared
Copy file name to clipboardExpand all lines: 1-js/04-object-basics/01-object/article.md
+10-9Lines changed: 10 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,7 @@ The resulting `user` object can be imagined as a cabinet with two signed files l
44
44
45
45

46
46
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.
48
48
49
49
Property values are accessible using the dot notation:
50
50
@@ -62,7 +62,7 @@ user.isAdmin = true;
62
62
63
63

64
64
65
-
To remove a property, we can use `delete` operator:
65
+
To remove a property, we can use the `delete` operator:
66
66
67
67
```js
68
68
deleteuser.age;
@@ -201,13 +201,13 @@ let bag = {
201
201
};
202
202
```
203
203
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.
205
205
206
206
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.
207
207
208
208
## Property value shorthand
209
209
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.
211
211
212
212
For instance:
213
213
@@ -252,7 +252,7 @@ let user = {
252
252
253
253
## Property names limitations
254
254
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.
256
256
257
257
But for an object property, there's no such restriction:
258
258
@@ -325,7 +325,7 @@ alert( "blabla" in user ); // false, user.blabla doesn't exist
325
325
326
326
Please note that on the left side of `in` there must be a *property name*. That's usually a quoted string.
327
327
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:
329
329
330
330
```js run
331
331
let user = { age:30 };
@@ -412,7 +412,7 @@ for (let code in codes) {
412
412
*/!*
413
413
```
414
414
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.
416
416
417
417
But if we run the code, we see a totally different picture:
418
418
@@ -424,9 +424,10 @@ The phone codes go in the ascending sorted order, because they are integers. So
The "integer property" term here means a string that can be converted to-and-from an integer without a change.
426
426
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:
428
428
429
429
```js run
430
+
// Number(...) explicitly converts to a number
430
431
// Math.trunc is a built-in function that removes the decimal part
0 commit comments