Skip to content

Commit ac57d1b

Browse files
authored
Merge branch 'master' into master
2 parents 4941164 + 5cdc613 commit ac57d1b

File tree

201 files changed

+1671
-1350
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

201 files changed

+1671
-1350
lines changed

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ Engines are complicated. But the basics are easy.
4141
2. Then it converts ("compiles") the script to the machine language.
4242
3. And then the machine code runs, pretty fast.
4343
44+
<<<<<<< HEAD
4445
The engine applies optimizations at each step of the process. It even watches the compiled script as it runs, analyzes the data that flows through it, and applies optimizations to the machine code based on that knowledge. When it's done, scripts run quite fast.
4546
'''
47+
=======
48+
The engine applies optimizations at each step of the process. It even watches the compiled script as it runs, analyzes the data that flows through it, and further optimizes the machine code based on that knowledge.
49+
```
50+
>>>>>>> fcfef6a07842ed56144e04a80c3a24de049a952a
4651
4752
## What can in-browser JavaScript do?
4853

@@ -66,7 +71,7 @@ JavaScript's abilities in the browser are limited for the sake of the user's saf
6671

6772
Examples of such restrictions include:
6873

69-
- JavaScript on a webpage may not read/write arbitrary files on the hard disk, copy them or execute programs. It has no direct access to OS system functions.
74+
- JavaScript on a webpage may not read/write arbitrary files on the hard disk, copy them or execute programs. It has no direct access to OS functions.
7075

7176
Modern browsers allow it to work with files, but the access is limited and only provided if the user does certain actions, like "dropping" a file into a browser window or selecting it via an '<input>' tag.
7277

1-js/01-getting-started/4-devtools/article.md

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333

3434
Τώρα μπορούμε να δούμε λάθη, και αυτό είναι αρκετό για μια αρχή. Θα επιστρέψουμε αργότερα στα developer tools και θα καλύψουμε λεπτομερέστερα το σφάλμα στο κεφάλαιο <info:debugging-chrome>.
3535

36+
```smart header="Multi-line input"
37+
Usually, when we put a line of code into the console, and then press `key:Enter`, it executes.
38+
39+
To insert multiple lines, press `key:Shift+Enter`. This way one can enter long fragments of JavaScript code.
40+
```
3641

3742
## Firefox, Edge, και άλλο
3843

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<body>
5+
6+
<script>
7+
alert( "I'm JavaScript!" );
8+
</script>
9+
10+
</body>
11+
12+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
[html src="index.html"]

1-js/02-first-steps/02-structure/article.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ But it should be two separate statements, not one. Such a merging in this case i
9494

9595
We recommend putting semicolons between statements even if they are separated by newlines. This rule is widely adopted by the community. Let's note once again -- *it is possible* to leave out semicolons most of the time. But it's safer -- especially for a beginner -- to use them.
9696

97-
## Comments
97+
## Comments [#code-comments]
9898

9999
As time goes on, programs become more and more complex. It becomes necessary to add *comments* which describe what the code does and why.
100100

@@ -136,7 +136,7 @@ alert('World');
136136
```
137137

138138
```smart header="Use hotkeys!"
139-
In most editors, a line of code can be commented out by pressing the `key:Ctrl+/` hotkey for a single-line comment and something like `key:Ctrl+Shift+/` -- for multiline comments (select a piece of code and press the hotkey). For Mac, try `key:Cmd` instead of `key:Ctrl`.
139+
In most editors, a line of code can be commented out by pressing the `key:Ctrl+/` hotkey for a single-line comment and something like `key:Ctrl+Shift+/` -- for multiline comments (select a piece of code and press the hotkey). For Mac, try `key:Cmd` instead of `key:Ctrl` and `key:Option` instead of `key:Shift`.
140140
```
141141

142142
````warn header="Nested comments are not supported!"

1-js/02-first-steps/03-strict-mode/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Only comments may appear above `"use strict"`.
4242
```warn header="There's no way to cancel `use strict`"
4343
There is no directive like `"no use strict"` that reverts the engine to old behavior.
4444

45-
Once we enter strict mode, there's no return.
45+
Once we enter strict mode, there's no going back.
4646
```
4747
4848
## Browser console

1-js/02-first-steps/05-types/article.md

+31-10
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ message = 123456;
1010

1111
Programming languages that allow such things are called "dynamically typed", meaning that there are data types, but variables are not bound to any of them.
1212

13-
There are seven basic data types in JavaScript. Here, we'll cover them in general and in the next chapters we'll talk about each of them in detail.
13+
There are eight basic data types in JavaScript. Here, we'll cover them in general and in the next chapters we'll talk about each of them in detail.
1414

15-
## A number
15+
## Number
1616

1717
```js
1818
let n = 123;
@@ -62,14 +62,33 @@ Special numeric values formally belong to the "number" type. Of course they are
6262

6363
We'll see more about working with numbers in the chapter <info:number>.
6464

65-
## A string
65+
## BigInt
66+
67+
In JavaScript, the "number" type cannot represent integer values larger than <code>2<sup>53</sup></code> (or less than <code>-2<sup>53</sup></code> for negatives), that's a technical limitation caused by their internal representation. That's about 16 decimal digits, so for most purposes the limitation isn't a problem, but sometimes we need really big numbers, e.g. for cryptography or microsecond-precision timestamps.
68+
69+
`BigInt` type was recently added to the language to represent integers of arbitrary length.
70+
71+
A `BigInt` is created by appending `n` to the end of an integer literal:
72+
73+
```js
74+
// the "n" at the end means it's a BigInt
75+
const bigInt = 1234567890123456789012345678901234567890n;
76+
```
77+
78+
As `BigInt` numbers are rarely needed, we devoted them a separate chapter <info:bigint>.
79+
80+
```smart header="Compatability issues"
81+
Right now `BigInt` is supported in Firefox and Chrome, but not in Safari/IE/Edge.
82+
```
83+
84+
## String
6685

6786
A string in JavaScript must be surrounded by quotes.
6887

6988
```js
7089
let str = "Hello";
7190
let str2 = 'Single quotes are ok too';
72-
let phrase = `can embed ${str}`;
91+
let phrase = `can embed another ${str}`;
7392
```
7493

7594
In JavaScript, there are 3 types of quotes.
@@ -78,7 +97,7 @@ In JavaScript, there are 3 types of quotes.
7897
2. Single quotes: `'Hello'`.
7998
3. Backticks: <code>&#96;Hello&#96;</code>.
8099

81-
Double and single quotes are "simple" quotes. There's no difference between them in JavaScript.
100+
Double and single quotes are "simple" quotes. There's practically no difference between them in JavaScript.
82101

83102
Backticks are "extended functionality" quotes. They allow us to embed variables and expressions into a string by wrapping them in `${…}`, for example:
84103

@@ -102,12 +121,12 @@ alert( "the result is ${1 + 2}" ); // the result is ${1 + 2} (double quotes do n
102121
We'll cover strings more thoroughly in the chapter <info:string>.
103122

104123
```smart header="There is no *character* type."
105-
In some languages, there is a special "character" type for a single character. For example, in the C language and in Java it is `char`.
124+
In some languages, there is a special "character" type for a single character. For example, in the C language and in Java it is called "char".
106125
107126
In JavaScript, there is no such type. There's only one type: `string`. A string may consist of only one character or many of them.
108127
```
109128

110-
## A boolean (logical type)
129+
## Boolean (logical type)
111130

112131
The boolean type has only two values: `true` and `false`.
113132

@@ -198,6 +217,8 @@ typeof undefined // "undefined"
198217

199218
typeof 0 // "number"
200219

220+
typeof 10n // "bigint"
221+
201222
typeof true // "boolean"
202223

203224
typeof "foo" // "string"
@@ -223,12 +244,12 @@ The last three lines may need additional explanation:
223244
2. The result of `typeof null` is `"object"`. That's wrong. It is an officially recognized error in `typeof`, kept for compatibility. Of course, `null` is not an object. It is a special value with a separate type of its own. So, again, this is an error in the language.
224245
3. The result of `typeof alert` is `"function"`, because `alert` is a function. We'll study functions in the next chapters where we'll also see that there's no special "function" type in JavaScript. Functions belong to the object type. But `typeof` treats them differently, returning `"function"`. That's not quite correct, but very convenient in practice.
225246

226-
227247
## Summary
228248

229-
There are 7 basic data types in JavaScript.
249+
There are 8 basic data types in JavaScript.
230250

231-
- `number` for numbers of any kind: integer or floating-point.
251+
- `number` for numbers of any kind: integer or floating-point, integers are limited by ±2<sup>53</sup>.
252+
- `bigint` is for integer numbers of arbitrary length.
232253
- `string` for strings. A string may have one or more characters, there's no separate single-character type.
233254
- `boolean` for `true`/`false`.
234255
- `null` for unknown values -- a standalone type that has a single value `null`.

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

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Μετατροπές Τύπων
22

3+
<<<<<<< HEAD
34
Τις περισσότερες φορές, οι τελεστές και οι συναρτήσεις μετατρέπουν αυτόματα, και στον σωστό τύπο, τις τιμές που δίνονται σε αυτές.
5+
=======
6+
Most of the time, operators and functions automatically convert the values given to them to the right type.
7+
>>>>>>> fcfef6a07842ed56144e04a80c3a24de049a952a
48
59
Για παράδειγμα, η `alert` μετατρέπει αυτόματα σε string οποιαδήποτε τιμή, ώστε να την εμφανίσει. Οι Μαθηματικές πράξεις μετατρέπουν τιμές σε νούμερα.
610

@@ -81,6 +85,7 @@ alert(Number(false)); // 0
8185

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

88+
<<<<<<< HEAD
8489
````smart header="Ο τελεστής '+' συνενώνει συμβολοσειρές"
8590
Σχεδόν όλες οι Μαθηματικές πράξεις μετατρέπουν τιμές σε αριθμούς. Μια ξεχωριστή εξαίρεση είναι ο τελεστής `+`. Έαν μία από τις προστιθέμενες τιμές είναι μια συμβολοσειρά, τότε και η άλλη μετατρέπεται σε συμβολοσειρά.
8691
@@ -93,6 +98,9 @@ alert( '1' + 2 ); // '12' (συμβολοσειρά στα αριστερά)
9398
9499
Αυτό συμβαίνει μόνο όταν τουλάχιστον μία από τις παραμέτρους είναι μια συμβολοσειρά. Διαφορετικά, οι τιμές μετατρέπονται σε αριθμούς.
95100
````
101+
=======
102+
Most mathematical operators also perform such conversion, we'll see that in the next chapter.
103+
>>>>>>> fcfef6a07842ed56144e04a80c3a24de049a952a
96104
97105
## Boolean Conversion
98106

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,17 @@ Here's an extract from the [precedence table](https://developer.mozilla.org/en/J
138138
| Precedence | Name | Sign |
139139
|------------|------|------|
140140
| ... | ... | ... |
141-
| 16 | unary plus | `+` |
142-
| 16 | unary negation | `-` |
143-
| 14 | multiplication | `*` |
144-
| 14 | division | `/` |
141+
| 17 | unary plus | `+` |
142+
| 17 | unary negation | `-` |
143+
| 15 | multiplication | `*` |
144+
| 15 | division | `/` |
145145
| 13 | addition | `+` |
146146
| 13 | subtraction | `-` |
147147
| ... | ... | ... |
148148
| 3 | assignment | `=` |
149149
| ... | ... | ... |
150150

151-
As we can see, the "unary plus" has a priority of `16` which is higher than the `13` of "addition" (binary plus). That's why, in the expression `"+apples + +oranges"`, unary pluses work before the addition.
151+
As we can see, the "unary plus" has a priority of `17` which is higher than the `13` of "addition" (binary plus). That's why, in the expression `"+apples + +oranges"`, unary pluses work before the addition.
152152
153153
## Assignment
154154

1-js/02-first-steps/08-comparison/1-comparison-questions/solution.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ null === +"\n0\n" → false
1313
Some of the reasons:
1414

1515
1. Obviously, true.
16-
2. Dictionary comparison, hence false.
16+
2. Dictionary comparison, hence false. `"a"` is smaller than `"p"`.
1717
3. Again, dictionary comparison, first char of `"2"` is greater than the first char of `"1"`.
1818
4. Values `null` and `undefined` equal each other only.
1919
5. Strict equality is strict. Different types from both sides lead to false.

1-js/02-first-steps/11-logical-operators/2-alert-or/solution.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ alert( alert(1) || 2 || alert(3) );
66

77
The call to `alert` does not return a value. Or, in other words, it returns `undefined`.
88

9-
1. The first OR `||` evaluates it's left operand `alert(1)`. That shows the first message with `1`.
9+
1. The first OR `||` evaluates its left operand `alert(1)`. That shows the first message with `1`.
1010
2. The `alert` returns `undefined`, so OR goes on to the second operand searching for a truthy value.
1111
3. The second operand `2` is truthy, so the execution is halted, `2` is returned and then shown by the outer alert.
1212

1-js/02-first-steps/12-while-for/article.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ For even values of `i`, the `continue` directive stops executing the body and pa
256256
````smart header="The `continue` directive helps decrease nesting"
257257
A loop that shows odd values could look like this:
258258

259-
```js
259+
```js run
260260
for (let i = 0; i < 10; i++) {
261261

262262
if (i % 2) {
@@ -268,7 +268,7 @@ for (let i = 0; i < 10; i++) {
268268

269269
From a technical point of view, this is identical to the example above. Surely, we can just wrap the code in an `if` block instead of using `continue`.
270270

271-
But as a side-effect, this created one more level of nesting (the `alert` call inside the curly braces). If the code inside of`if` is longer than a few lines, that may decrease the overall readability.
271+
But as a side-effect, this created one more level of nesting (the `alert` call inside the curly braces). If the code inside of `if` is longer than a few lines, that may decrease the overall readability.
272272
````
273273
274274
````warn header="No `break/continue` to the right side of '?'"

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ There may be many occurrences of `return` in a single function. For instance:
266266
267267
```js run
268268
function checkAge(age) {
269-
if (age > 18) {
269+
if (age >= 18) {
270270
*!*
271271
return true;
272272
*/!*

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

+1-107
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Function expressions and arrows
1+
# Function expressions
22

33
In JavaScript, a function is not a "magical language structure", but a special kind of value.
44

@@ -355,107 +355,6 @@ That's also better for readability, as it's easier to look up `function f(…) {
355355
...But if a Function Declaration does not suit us for some reason, or we need a conditional declaration (we've just seen an example), then Function Expression should be used.
356356
```
357357

358-
359-
## Arrow functions [#arrow-functions]
360-
361-
There's one more very simple and concise syntax for creating functions, that's often better than Function Expressions. It's called "arrow functions", because it looks like this:
362-
363-
364-
```js
365-
let func = (arg1, arg2, ...argN) => expression
366-
```
367-
368-
...This creates a function `func` that has arguments `arg1..argN`, evaluates the `expression` on the right side with their use and returns its result.
369-
370-
In other words, it's roughly the same as:
371-
372-
```js
373-
let func = function(arg1, arg2, ...argN) {
374-
return expression;
375-
};
376-
```
377-
378-
...But much more concise.
379-
380-
Let's see an example:
381-
382-
```js run
383-
let sum = (a, b) => a + b;
384-
385-
/* The arrow function is a shorter form of:
386-
387-
let sum = function(a, b) {
388-
return a + b;
389-
};
390-
*/
391-
392-
alert( sum(1, 2) ); // 3
393-
394-
```
395-
396-
If we have only one argument, then parentheses around parameters can be omitted, making that even shorter:
397-
398-
```js run
399-
// same as
400-
// let double = function(n) { return n * 2 }
401-
*!*
402-
let double = n => n * 2;
403-
*/!*
404-
405-
alert( double(3) ); // 6
406-
```
407-
408-
If there are no arguments, parentheses should be empty (but they should be present):
409-
410-
```js run
411-
let sayHi = () => alert("Hello!");
412-
413-
sayHi();
414-
```
415-
416-
Arrow functions can be used in the same way as Function Expressions.
417-
418-
For instance, here's the rewritten example with `welcome()`:
419-
420-
```js run
421-
let age = prompt("What is your age?", 18);
422-
423-
let welcome = (age < 18) ?
424-
() => alert('Hello') :
425-
() => alert("Greetings!");
426-
427-
welcome(); // ok now
428-
```
429-
430-
Arrow functions may appear unfamiliar and not very readable at first, but that quickly changes as the eyes get used to the structure.
431-
432-
They are very convenient for simple one-line actions, when we're just too lazy to write many words.
433-
434-
```smart header="Multiline arrow functions"
435-
436-
The examples above took arguments from the left of `=>` and evaluated the right-side expression with them.
437-
438-
Sometimes we need something a little bit more complex, like multiple expressions or statements. It is also possible, but we should enclose them in curly braces. Then use a normal `return` within them.
439-
440-
Like this:
441-
442-
```js run
443-
let sum = (a, b) => { // the curly brace opens a multiline function
444-
let result = a + b;
445-
*!*
446-
return result; // if we use curly braces, use return to get results
447-
*/!*
448-
};
449-
450-
alert( sum(1, 2) ); // 3
451-
```
452-
453-
```smart header="More to come"
454-
Here we praised arrow functions for brevity. But that's not all! Arrow functions have other interesting features. We'll return to them later in the chapter <info:arrow-functions>.
455-
456-
For now, we can already use arrow functions for one-line actions and callbacks.
457-
```
458-
459358
## Summary
460359

461360
- Functions are values. They can be assigned, copied or declared in any place of the code.
@@ -467,8 +366,3 @@ For now, we can already use arrow functions for one-line actions and callbacks.
467366
In most cases when we need to declare a function, a Function Declaration is preferable, because it is visible prior to the declaration itself. That gives us more flexibility in code organization, and is usually more readable.
468367

469368
So we should use a Function Expression only when a Function Declaration is not fit for the task. We've seen a couple of examples of that in this chapter, and will see more in the future.
470-
471-
Arrow functions are handy for one-liners. They come in two flavors:
472-
473-
1. Without curly braces: `(...args) => expression` -- the right side is an expression: the function evaluates it and returns the result.
474-
2. With curly braces: `(...args) => { body }` -- brackets allow us to write multiple statements inside the function, but we need an explicit `return` to return something.

0 commit comments

Comments
 (0)