Skip to content

Commit 7479ca9

Browse files
authored
Merge pull request #104 from javascript-tutorial/sync-1edb0a38
Sync with upstream @ 1edb0a3
2 parents 1e2a27e + 120dccf commit 7479ca9

22 files changed

Lines changed: 107 additions & 62 deletions

File tree

1-js/01-getting-started/1-intro/article.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,17 @@
3333

3434
Τα engines είναι περίπλοκοι. Αλλά τα βασικά είναι εύκολα.
3535

36+
3637
1. Το engine (ενσωματωμένος αν είναι πρόγραμμα περιήγησης) διαβάζει ("αναλύει") τα script.
3738
2. Στη συνέχεια μετατρέπει ("μεταγλώττιση") το script στη γλώσσα του μηχανήματος.
3839
3. Ύστερα ο κώδικας του μηχανήματος τρέχει, αρκετά γρήγορα.
3940
Το engine εφαρμόζει βελτιστοποιήσει σε κάθε βήμα της διαδικασίας. Παρακολουθεί ακόμη και το μεταγλωττισμένο script καθώς εκτελείται, αναλύει τα δεδομένα που ρέουν μέσα από αυτό και εφαρμόζει βελτιστοποιήσεις στον κώδικα του μηχανήματος βάσει αυτής της γνώσης. Όταν ολοκληρωθεί, τα script εκτελούνται αρκετά γρήγορα.
40-
'''
4141

4242
## Τι μπορεί να κάνει η JavaScript στο πρόγραμμα περιήγησης?
4343

4444
Η σύγχρονη JavaScript είναι μια "ασφαλής" γλώσσα προγραμματισμού. Δεν παρέχει low-level πρόσβαση στη μνήμη ή στη CPU, επειδή δημιουργήθηκε αρχικά για προγράμματα περιήγησης που δεν το χρειάζονται.
4545

46+
4647
Οι δυνατότητες της JavaScript εξαρτώνται σε μεγάλο βαθμό από το περιβάλλον στο οποίο εκτελείται. Για παράδειγμα, το [Node.js] (https://wikipedia.org/wiki/Node.js) υποστηρίζει λειτουργίες που επιτρέπουν στην JavaScript να διαβάζει/γράφει αυθαίρετα αρχεία, να εκτελεί αιτήματα δικτύου, και τα λοιπά.
4748

4849
Η JavaScript στο πρόγραμμα περιήγησης μπορεί να κάνει ό, τι σχετίζεται με τη διαχείριση ιστοσελίδων, την αλληλεπίδραση με τον χρήστη και τον διακομιστή ιστού.
@@ -103,21 +104,11 @@
103104

104105
Παραδείγματα τέτοιων γλωσσών:
105106

106-
<<<<<<< HEAD
107107
- [CoffeeScript](http://coffeescript.org/) είναι "syntactic sugar" για την JavaScript. Εισάγει συντομότερη σύνταξη, επιτρέποντάς μας να γράψουμε σαφέστερο και ακριβέστερο κώδικα.
108108
Συνήθως, στούς Ruby devs αρέσει.
109109
- [TypeScript](http://www.typescriptlang.org/) επικεντρώνεται στην προσθήκη "αυστηρής πληκτρολόγησης δεδομένων" για απλοποίηση της ανάπτυξης και υποστήριξης σύνθετων συστημάτων. Αναπτύσσεται από τη Microsoft.
110110
- [Flow](http://flow.org/) προσθέτει επίσης πληκτρολόγηση δεδομένων, αλλά με διαφορετικό τρόπο. Αναπτύχθηκε από το Facebook.
111111
- [Dart](https://www.dartlang.org/) είναι μια αυτόνομη γλώσσα που έχει τη δική της μηχανή που λειτουργεί σε περιβάλλοντα εκτός προγράμματος περιήγησης (όπως εφαρμογές για κινητά), αλλά μπορεί επίσης να μεταφερθεί σε JavaScript. Αναπτύχθηκε από την Google.
112-
- [Brython](https://brython.info/) είναι ένας Python transpiler σε JavaScript που επιτρέπει την εγγραφή εφαρμογής σε πλήρη Python χωρίς JavaScript.
113-
=======
114-
- [CoffeeScript](https://coffeescript.org/) is a "syntactic sugar" for JavaScript. It introduces shorter syntax, allowing us to write clearer and more precise code. Usually, Ruby devs like it.
115-
- [TypeScript](https://www.typescriptlang.org/) is concentrated on adding "strict data typing" to simplify the development and support of complex systems. It is developed by Microsoft.
116-
- [Flow](https://flow.org/) also adds data typing, but in a different way. Developed by Facebook.
117-
- [Dart](https://www.dartlang.org/) is a standalone language that has its own engine that runs in non-browser environments (like mobile apps), but also can be transpiled to JavaScript. Developed by Google.
118-
- [Brython](https://brython.info/) is a Python transpiler to JavaScript that enables the writing of applications in pure Python without JavaScript.
119-
- [Kotlin](https://kotlinlang.org/docs/reference/js-overview.html) is a modern, concise and safe programming language that can target the browser or Node.
120-
>>>>>>> 30a5d5e2a7c3504c9afd5028f83f4a696e60aede
121112

122113
Υπάρχουν περισσότερα. Φυσικά, ακόμη και αν χρησιμοποιούμε μία από τις μεταγλωττισμένες γλώσσες, πρέπει επίσης να γνωρίζουμε τη JavaScript για να κατανοήσουμε πραγματικά τι κάνουμε.
123114

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ alert(age); // NaN, η μετατροπή απέτυχε
6666

6767
Κανόνες αριθμητικών μετατροπών:
6868

69+
6970
| Τιμή | Γίνεται... |
7071
| ------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
7172
| `undefined` | `NaN` |
@@ -133,7 +134,7 @@ alert(Boolean("")); // false
133134
|-------|-------------|
134135
|`undefined`|`NaN`|
135136
|`null`|`0`|
136-
|<code>true&nbsp;/&nbsp;false</code> | `1 / 0` |
137+
137138
| `string` | Η συμβολοσειρά διαβάζεται "όπως είναι", τα κενά και από τις δύο πλευρές αγνοούνται. Μια άδεια συμβολοσειρά γίνεται `0`. Ένα σφάλμα δίνει `NaN`. |
138139
139140

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,13 @@ alert( +apples + +oranges ); // 5
187187
| Precedence | Name | Sign |
188188
|------------|------|------|
189189
| ... | ... | ... |
190-
| 15 | unary plus | `+` |
191-
| 15 | unary negation | `-` |
192-
| 14 | exponentiation | `**` |
193-
| 13 | multiplication | `*` |
194-
| 13 | division | `/` |
195-
| 12 | addition | `+` |
196-
| 12 | subtraction | `-` |
190+
| 14 | unary plus | `+` |
191+
| 14 | unary negation | `-` |
192+
| 13 | exponentiation | `**` |
193+
| 12 | multiplication | `*` |
194+
| 12 | division | `/` |
195+
| 11 | addition | `+` |
196+
| 11 | subtraction | `-` |
197197
| ... | ... | ... |
198198
| 2 | assignment | `=` |
199199
| ... | ... | ... |
@@ -202,7 +202,6 @@ alert( +apples + +oranges ); // 5
202202
203203
## Ανάθεση
204204
205-
206205
Ας σημειώσουμε ότι μια ανάθεση `=` είναι επίσης τελεστής. Παρατίθεται στον πίνακα προτεραιότητας με την πολύ χαμηλή προτεραιότητα του `3`.
207206
208207
Γι 'αυτό, όταν εκχωρούμε μια μεταβλητή, όπως `x = 2 * 2 + 1`, οι υπολογισμοί γίνονται πρώτα και στη συνέχεια αξιολογείται το `=`, αποθηκεύοντας το αποτέλεσμα στο `x`.
@@ -297,10 +296,9 @@ alert( n ); // 14
297296
```js run
298297
let n = 2;
299298
300-
n *= 3 + 5;
299+
n *= 3 + 5; // right part evaluated first, same as n *= 8
301300
302301
alert( n ); // 16 (το σωστό μέρος αξιολογήθηκε πρώτα, το ίδια και για το n *= 8)
303-
```
304302
305303
## Αύξηση/μείωση
306304
@@ -368,7 +366,7 @@ alert(a); // *!*1*/!*
368366
++counter;
369367
alert( counter ); // 2, οι παραπάνω γραμμές έκαναν το ίδιο
370368
```
371-
- Εάν θέλουμε να αυξήσουμε μια τιμή *και* να χρησιμοποιήσουμε αμέσως το αποτέλεσμα του τελεστή, χρειαζόμαστε τη φόρμα prefix:
369+
- Εάν θέλουμε να αυξήσουμε μια τιμή *και* να χρησιμοποιήσουμε αμέσως το αποτέλεσμα του τελεστή, χρειαζόμαστε τη φόρμα prefix:
372370

373371
```js run
374372
let counter = 0;

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

Lines changed: 5 additions & 5 deletions
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+
// body
2828
}
2929
```
3030

@@ -193,6 +193,10 @@ showMessage("Ann"); // Ann: δεν έχει δοθεί κείμενο
193193
194194
Τώρα, εάν η παράμετρος `text` δεν δοθεί, θα λάβει την τιμή `"no text given"`.
195195
196+
```js
197+
showMessage("Ann", undefined); // Ann: no text given
198+
```
199+
196200
Εδώ `"no text given"` είναι μια συμβολοσειρά, αλλά μπορεί να είναι μια πιο περίπλοκη έκφραση, η οποία αξιολογείται και αναθέτετε μόνο εάν λείπει η παράμετρος. Αυτό είναι επίσης δυνατό:
197201
198202
```js run
@@ -470,11 +474,7 @@ function name(parameters, delimited, by, comma) {
470474
471475
Για να κάνετε τον κώδικα καθαρό και κατανοητό, συνίσταται η χρήση κυρίως τοπικών μεταβλητών και παραμέτρων στη συνάρτηση, όχι εξωτερικών μεταβλητών.
472476
473-
<<<<<<< HEAD
474477
Είναι πάντα πιο εύκολο να κατανοήσουμε μια συνάρτηση που παίρνει παραμέτρους, δουλεύει μαζί τους και επιστρέφει ένα αποτέλεσμα, παρά μια συνάρτηση που δεν έχει παραμέτρους, αλλά τροποποιεί τις εξωτερικές μεταβλητές ως side-effect.
475-
=======
476-
It is always easier to understand a function which gets parameters, works with them and returns a result than a function which gets no parameters, but modifies outer variables as a side effect.
477-
>>>>>>> 206485fc3a5465f961608b6e7303fae2e1a0e0b5
478478
479479
Ονομασία συναρτήσεων:
480480

1-js/03-code-quality/05-testing-mocha/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ So, the development is *iterative*. We write the spec, implement it, make sure t
7979

8080
Let's see this development flow in our practical case.
8181

82-
The first step is already complete: we have an initial spec for `pow`. Now, before making the implementation, let's use few JavaScript libraries to run the tests, just to see that they are working (they will all fail).
82+
The first step is already complete: we have an initial spec for `pow`. Now, before making the implementation, let's use a few JavaScript libraries to run the tests, just to see that they are working (they will all fail).
8383

8484
## The spec in action
8585

1-js/04-object-basics/09-object-toprimitive/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ As we can see from the code, `user` becomes a self-descriptive string or a money
136136

137137
If there's no `Symbol.toPrimitive` then JavaScript tries to find methods `toString` and `valueOf`:
138138

139-
- For the `"string"` hint: call `toString` method, and if it doesn't exist, then `valueOf` (so `toString` has the priority for string conversions).
140-
- For other hints: `valueOf`, and if it doesn't exist, then `toString` (so `valueOf` has the priority for maths).
139+
- For the `"string"` hint: call `toString` method, and if it doesn't exist or if it returns an object instead of a primitive value, then call `valueOf` (so `toString` has the priority for string conversions).
140+
- For other hints: call `valueOf`, and if it doesn't exist or if it returns an object instead of a primitive value, then call `toString` (so `valueOf` has the priority for maths).
141141

142142
Methods `toString` and `valueOf` come from ancient times. They are not symbols (symbols did not exist that long ago), but rather "regular" string-named methods. They provide an alternative "old-style" way to implement the conversion.
143143

1-js/05-data-types/02-number/article.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,15 +334,44 @@ alert( isFinite(num) );
334334

335335
Please note that an empty or a space-only string is treated as `0` in all numeric functions including `isFinite`.
336336

337-
```smart header="Compare with `Object.is`"
337+
````smart header="`Number.isNaN` and `Number.isFinite`"
338+
[Number.isNaN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN) and [Number.isFinite](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite) methods are the more "strict" versions of `isNaN` and `isFinite` functions. They do not autoconvert their argument into a number, but check if it belongs to the `number` type instead.
339+
340+
- `Number.isNaN(value)` returns `true` if the argument belongs to the `number` type and it is `NaN`. In any other case it returns `false`.
341+
342+
```js run
343+
alert( Number.isNaN(NaN) ); // true
344+
alert( Number.isNaN("str" / 2) ); // true
345+
346+
// Note the difference:
347+
alert( Number.isNaN("str") ); // false, because "str" belongs to the string type, not the number type
348+
alert( isNaN("str") ); // true, because isNaN converts string "str" into a number and gets NaN as a result of this conversion
349+
```
350+
351+
- `Number.isFinite(value)` returns `true` if the argument belongs to the `number` type and it is not `NaN/Infinity/-Infinity`. In any other case it returns `false`.
352+
353+
```js run
354+
alert( Number.isFinite(123) ); // true
355+
alert( Number.isFinite(Infinity) ); //false
356+
alert( Number.isFinite(2 / 0) ); // false
357+
358+
// Note the difference:
359+
alert( Number.isFinite("123") ); // false, because "123" belongs to the string type, not the number type
360+
alert( isFinite("123") ); // true, because isFinite converts string "123" into a number 123
361+
```
362+
363+
In a way, `Number.isNaN` and `Number.isFinite` are simpler and more straightforward than `isNaN` and `isFinite` functions. In practice though, `isNaN` and `isFinite` are mostly used, as they're shorter to write.
364+
````
365+
366+
```smart header="Comparison with `Object.is`"
338367
There is a special built-in method `Object.is` that compares values like `===`, but is more reliable for two edge cases:
339368

340369
1. It works with `NaN`: `Object.is(NaN, NaN) === true`, that's a good thing.
341370
2. Values `0` and `-0` are different: `Object.is(0, -0) === false`, technically that's true, because internally the number has a sign bit that may be different even if all other bits are zeroes.
342371

343372
In all other cases, `Object.is(a, b)` is the same as `a === b`.
344373

345-
This way of comparison is often used in JavaScript specification. When an internal algorithm needs to compare two values for being exactly the same, it uses `Object.is` (internally called [SameValue](https://tc39.github.io/ecma262/#sec-samevalue)).
374+
We mention `Object.is` here, because it's often used in JavaScript specification. When an internal algorithm needs to compare two values for being exactly the same, it uses `Object.is` (internally called [SameValue](https://tc39.github.io/ecma262/#sec-samevalue)).
346375
```
347376

348377

@@ -435,7 +464,9 @@ For different numeral systems:
435464
For regular number tests:
436465

437466
- `isNaN(value)` converts its argument to a number and then tests it for being `NaN`
438-
- `isFinite(value)` converts its argument to a number and returns `true` if it's a regular number, not `NaN/Infinity/-Infinity`
467+
- `Number.isNaN(value)` checks whether its argument belongs to the `number` type, and if so, tests it for being `NaN`
468+
- `isFinite(value)` converts its argument to a number and then tests it for not being `NaN/Infinity/-Infinity`
469+
- `Number.isFinite(value)` checks whether its argument belongs to the `number` type, and if so, tests it for not being `NaN/Infinity/-Infinity`
439470

440471
For converting values like `12pt` and `100px` to a number:
441472

1-js/05-data-types/03-string/article.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ There are 3 methods in JavaScript to get a substring: `substring`, `substr` and
445445
alert( str.substr(-4, 2) ); // 'gi', from the 4th position get 2 characters
446446
```
447447

448+
This method resides in the [Annex B](https://tc39.es/ecma262/#sec-string.prototype.substr) of the language specification. It means that only browser-hosted Javascript engines should support it, and it's not recommended to use it. In practice, it's supported everywhere.
449+
448450
Let's recap these methods to avoid any confusion:
449451

450452
| method | selects... | negatives |

1-js/05-data-types/05-array-methods/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ The method [arr.lastIndexOf](mdn:js/Array/lastIndexOf) is the same as `indexOf`,
262262
```js run
263263
let fruits = ['Apple', 'Orange', 'Apple']
264264

265-
alert( arr.indexOf('Apple') ); // 0 (first Apple)
266-
alert( arr.lastIndexOf('Apple') ); // 2 (last Apple)
265+
alert( fruits.indexOf('Apple') ); // 0 (first Apple)
266+
alert( fruits.lastIndexOf('Apple') ); // 2 (last Apple)
267267
```
268268

269269
````smart header="The `includes` method handles `NaN` correctly"

1-js/05-data-types/06-iterable/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ alert(arr.pop()); // World (method works)
218218

219219
The same happens for an iterable:
220220

221-
```js
221+
```js run
222222
// assuming that range is taken from the example above
223223
let arr = Array.from(range);
224224
alert(arr); // 1,2,3,4,5 (array toString conversion works)
@@ -233,7 +233,7 @@ The optional second argument `mapFn` can be a function that will be applied to e
233233

234234
For instance:
235235

236-
```js
236+
```js run
237237
// assuming that range is taken from the example above
238238

239239
// square each number

0 commit comments

Comments
 (0)