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/01-getting-started/1-intro/article.md
+2-11Lines changed: 2 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,16 +33,17 @@
33
33
34
34
Τα engines είναι περίπλοκοι. Αλλά τα βασικά είναι εύκολα.
35
35
36
+
36
37
1. Το engine (ενσωματωμένος αν είναι πρόγραμμα περιήγησης) διαβάζει ("αναλύει") τα script.
37
38
2. Στη συνέχεια μετατρέπει ("μεταγλώττιση") το script στη γλώσσα του μηχανήματος.
38
39
3. Ύστερα ο κώδικας του μηχανήματος τρέχει, αρκετά γρήγορα.
39
40
Το engine εφαρμόζει βελτιστοποιήσει σε κάθε βήμα της διαδικασίας. Παρακολουθεί ακόμη και το μεταγλωττισμένο script καθώς εκτελείται, αναλύει τα δεδομένα που ρέουν μέσα από αυτό και εφαρμόζει βελτιστοποιήσεις στον κώδικα του μηχανήματος βάσει αυτής της γνώσης. Όταν ολοκληρωθεί, τα script εκτελούνται αρκετά γρήγορα.
40
-
'''
41
41
42
42
## Τι μπορεί να κάνει η JavaScript στο πρόγραμμα περιήγησης?
43
43
44
44
Η σύγχρονη JavaScript είναι μια "ασφαλής" γλώσσα προγραμματισμού. Δεν παρέχει low-level πρόσβαση στη μνήμη ή στη CPU, επειδή δημιουργήθηκε αρχικά για προγράμματα περιήγησης που δεν το χρειάζονται.
45
45
46
+
46
47
Οι δυνατότητες της JavaScript εξαρτώνται σε μεγάλο βαθμό από το περιβάλλον στο οποίο εκτελείται. Για παράδειγμα, το [Node.js] (https://wikipedia.org/wiki/Node.js) υποστηρίζει λειτουργίες που επιτρέπουν στην JavaScript να διαβάζει/γράφει αυθαίρετα αρχεία, να εκτελεί αιτήματα δικτύου, και τα λοιπά.
47
48
48
49
Η JavaScript στο πρόγραμμα περιήγησης μπορεί να κάνει ό, τι σχετίζεται με τη διαχείριση ιστοσελίδων, την αλληλεπίδραση με τον χρήστη και τον διακομιστή ιστού.
@@ -103,21 +104,11 @@
103
104
104
105
Παραδείγματα τέτοιων γλωσσών:
105
106
106
-
<<<<<<< HEAD
107
107
-[CoffeeScript](http://coffeescript.org/) είναι "syntactic sugar" για την JavaScript. Εισάγει συντομότερη σύνταξη, επιτρέποντάς μας να γράψουμε σαφέστερο και ακριβέστερο κώδικα.
108
108
Συνήθως, στούς Ruby devs αρέσει.
109
109
-[TypeScript](http://www.typescriptlang.org/) επικεντρώνεται στην προσθήκη "αυστηρής πληκτρολόγησης δεδομένων" για απλοποίηση της ανάπτυξης και υποστήριξης σύνθετων συστημάτων. Αναπτύσσεται από τη Microsoft.
110
110
-[Flow](http://flow.org/) προσθέτει επίσης πληκτρολόγηση δεδομένων, αλλά με διαφορετικό τρόπο. Αναπτύχθηκε από το Facebook.
111
111
-[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
121
112
122
113
Υπάρχουν περισσότερα. Φυσικά, ακόμη και αν χρησιμοποιούμε μία από τις μεταγλωττισμένες γλώσσες, πρέπει επίσης να γνωρίζουμε τη JavaScript για να κατανοήσουμε πραγματικά τι κάνουμε.
| `string` | Η συμβολοσειρά διαβάζεται "όπως είναι", τα κενά και από τις δύο πλευρές αγνοούνται. Μια άδεια συμβολοσειρά γίνεται `0`. Ένα σφάλμα δίνει `NaN`. |
Ας σημειώσουμε ότι μια ανάθεση `=` είναι επίσης τελεστής. Παρατίθεται στον πίνακα προτεραιότητας με την πολύ χαμηλή προτεραιότητα του `3`.
207
206
208
207
Γι 'αυτό, όταν εκχωρούμε μια μεταβλητή, όπως `x = 2 * 2 + 1`, οι υπολογισμοί γίνονται πρώτα και στη συνέχεια αξιολογείται το `=`, αποθηκεύοντας το αποτέλεσμα στο `x`.
@@ -297,10 +296,9 @@ alert( n ); // 14
297
296
```js run
298
297
let n = 2;
299
298
300
-
n *= 3 + 5;
299
+
n *= 3 + 5; // right part evaluated first, same as n *= 8
301
300
302
301
alert( n ); // 16 (το σωστό μέρος αξιολογήθηκε πρώτα, το ίδια και για το n *= 8)
303
-
```
304
302
305
303
## Αύξηση/μείωση
306
304
@@ -368,7 +366,7 @@ alert(a); // *!*1*/!*
368
366
++counter;
369
367
alert( counter ); // 2, οι παραπάνω γραμμές έκαναν το ίδιο
370
368
```
371
-
- Εάν θέλουμε να αυξήσουμε μια τιμή *και* να χρησιμοποιήσουμε αμέσως το αποτέλεσμα του τελεστή, χρειαζόμαστε τη φόρμα prefix:
369
+
- Εάν θέλουμε να αυξήσουμε μια τιμή *και* να χρησιμοποιήσουμε αμέσως το αποτέλεσμα του τελεστή, χρειαζόμαστε τη φόρμα prefix:
@@ -193,6 +193,10 @@ showMessage("Ann"); // Ann: δεν έχει δοθεί κείμενο
193
193
194
194
Τώρα, εάν η παράμετρος `text` δεν δοθεί, θα λάβει την τιμή `"no text given"`.
195
195
196
+
```js
197
+
showMessage("Ann", undefined); // Ann: no text given
198
+
```
199
+
196
200
Εδώ `"no text given"` είναι μια συμβολοσειρά, αλλά μπορεί να είναι μια πιο περίπλοκη έκφραση, η οποία αξιολογείται και αναθέτετε μόνο εάν λείπει η παράμετρος. Αυτό είναι επίσης δυνατό:
197
201
198
202
```js run
@@ -470,11 +474,7 @@ function name(parameters, delimited, by, comma) {
470
474
471
475
Για να κάνετε τον κώδικα καθαρό και κατανοητό, συνίσταται η χρήση κυρίως τοπικών μεταβλητών και παραμέτρων στη συνάρτηση, όχι εξωτερικών μεταβλητών.
472
476
473
-
<<<<<<< HEAD
474
477
Είναι πάντα πιο εύκολο να κατανοήσουμε μια συνάρτηση που παίρνει παραμέτρους, δουλεύει μαζί τους και επιστρέφει ένα αποτέλεσμα, παρά μια συνάρτηση που δεν έχει παραμέτρους, αλλά τροποποιεί τις εξωτερικές μεταβλητές ως 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.
Copy file name to clipboardExpand all lines: 1-js/03-code-quality/05-testing-mocha/article.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,7 +79,7 @@ So, the development is *iterative*. We write the spec, implement it, make sure t
79
79
80
80
Let's see this development flow in our practical case.
81
81
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).
Copy file name to clipboardExpand all lines: 1-js/04-object-basics/09-object-toprimitive/article.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -136,8 +136,8 @@ As we can see from the code, `user` becomes a self-descriptive string or a money
136
136
137
137
If there's no `Symbol.toPrimitive` then JavaScript tries to find methods `toString` and `valueOf`:
138
138
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).
141
141
142
142
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.
Copy file name to clipboardExpand all lines: 1-js/05-data-types/02-number/article.md
+34-3Lines changed: 34 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -334,15 +334,44 @@ alert( isFinite(num) );
334
334
335
335
Please note that an empty or a space-only string is treated as `0` in all numeric functions including `isFinite`.
336
336
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`"
338
367
There is a special built-in method `Object.is` that compares values like `===`, but is more reliable for two edge cases:
339
368
340
369
1. It works with `NaN`: `Object.is(NaN, NaN) === true`, that's a good thing.
341
370
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.
342
371
343
372
In all other cases, `Object.is(a, b)` is the same as `a === b`.
344
373
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)).
346
375
```
347
376
348
377
@@ -435,7 +464,9 @@ For different numeral systems:
435
464
For regular number tests:
436
465
437
466
- `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`
439
470
440
471
For converting values like `12pt` and `100px` to a number:
Copy file name to clipboardExpand all lines: 1-js/05-data-types/03-string/article.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -445,6 +445,8 @@ There are 3 methods in JavaScript to get a substring: `substring`, `substr` and
445
445
alert( str.substr(-4, 2) ); // 'gi', from the 4th position get 2 characters
446
446
```
447
447
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.
0 commit comments