Skip to content

Commit 6b58399

Browse files
authored
Merge pull request #49 from javascript-tutorial/sync-291b5c05
Sync with upstream @ 291b5c0
2 parents e189f19 + 4100907 commit 6b58399

File tree

120 files changed

+671
-381
lines changed

Some content is hidden

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

120 files changed

+671
-381
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ Selaimeen on upotettu moottori, jota kutsutaan joskus "JavaScript-virtuaalikonee
2424

2525
Eri moottoreilla on omia kutsumanimiä. Esimerkiksi:
2626

27-
- [V8](https://fi.wikipedia.org/wiki/V8_(JavaScript-moottori)) -- Chromessa ja Operassa.
27+
- [V8](https://fi.wikipedia.org/wiki/V8_(JavaScript-moottori)) -- Chromessa, Operassa ja Edgessä.
2828
- [SpiderMonkey](https://en.wikipedia.org/wiki/SpiderMonkey) -- Firefoxissa.
2929
- ...Lisäksi on muitakin kutsumanimiä kuten "Chakra" IE:lle, "JavaScriptCore", "Nitro" ja "SquirrelFish" Safarille, jne.
3030

31-
Yllä luetellut termit on hyvä muistaa, koska niitä käytetään internetin sovelluskehitykseen liittyvissä artikkeleissa. Me tulemme myös käyttämään niitä. Jos esimerkiksi "V8 tukee toimintoa X", se todennäköisesti toimii Chromessa ja Operassa.
31+
Yllä luetellut termit on hyvä muistaa, koska niitä käytetään internetin sovelluskehitykseen liittyvissä artikkeleissa. Me tulemme myös käyttämään niitä. Jos esimerkiksi "V8 tukee toimintoa X", se todennäköisesti toimii Chromessa, Operassa ja Edgessä.
3232

3333
```smart header="Miten moottorit toimivat?"
3434
@@ -59,7 +59,7 @@ Selaimessa JavaScript voi esimerkiksi:
5959

6060
## Mitä JavaScript EI VOI tehdä selaimessa?
6161

62-
JavaScriptin kyvyt selaimessa on rajoitettu käyttäjän turvallisuuden vuoksi. Tavoitteena on estää pahaa nettisivua pääsemästä käsiksi yksityisiin tietoihin tai vahingoittamasta käyttäjän tietoja.
62+
JavaScriptin kykyjä selaimessa on rajoitettu käyttäjän turvallisuuden vuoksi. Tavoitteena on estää pahaa nettisivua pääsemästä käsiksi yksityisiin tietoihin tai vahingoittamasta käyttäjän tietoja.
6363

6464
Esimerkkejä tällaisista rajoituksista ovat:
6565

@@ -117,6 +117,6 @@ Lisääkin esimerkkejä löytyy. Silti, vaikka käytämme jotain muunnettavaa ki
117117

118118
## Yhteenveto
119119

120-
- JavaScript suunniteltiin alunperin vain selaimeen, mutta sitä käytetään nykyisin myös monissa muissa ympäristöissä.
120+
- JavaScript suunniteltiin alunperin vain selaimessa käytettäväksi kieleksi, mutta sitä käytetään nykyisin myös monissa muissa ympäristöissä.
121121
- JavaScriptillä on nykyisin uniikki asema laajimmin käytettynä selainkielenä, joka integroituu täysin HTML:ään ja CSS:ään.
122122
- Monet JavaScriptiksi "muunnettavat" kielet tuovat mukanaan tiettyjä toimintoja. On suositeltavaa tutustua niihin, ainakin lyhyesti, kun JavaScript on hallussa.

1-js/01-getting-started/3-code-editors/article.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,18 @@ Käytännössä kevyihin editoreihin voi olla saatavilla monia lisäosia mukaan
3131

3232
Seuraavat vaihtoehdot ansaitsevat huomiosi:
3333

34+
<<<<<<< HEAD
3435
- [Atom](https://atom.io/) (järjestelmäriippumaton, ilmainen).
3536
- [Visual Studio Code](https://code.visualstudio.com/) (järjestelmäriippumaton, ilmainen).
3637
- [Sublime Text](http://www.sublimetext.com) (järjestelmäriippumaton, shareware).
3738
- [Notepad++](https://notepad-plus-plus.org/) (Windows, ilmainen).
3839
- [Vim](http://www.vim.org/) ja [Emacs](https://www.gnu.org/software/emacs/) ovat myös siistejä, jos tiedät, miten niitä käytetään.
40+
=======
41+
- [Atom](https://atom.io/) (cross-platform, free).
42+
- [Sublime Text](http://www.sublimetext.com) (cross-platform, shareware).
43+
- [Notepad++](https://notepad-plus-plus.org/) (Windows, free).
44+
- [Vim](http://www.vim.org/) and [Emacs](https://www.gnu.org/software/emacs/) are also cool if you know how to use them.
45+
>>>>>>> 291b5c05b99452cf8a0d32bd32426926dbcc0ce0
3946
4047
## Ei riidellä
4148

1-js/02-first-steps/01-hello-world/article.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ Skriptitiedostot liitetään HTML:ään `src` (suom. lähde) attribuutilla:
7373
<script src="/polku/tiedostoon/script.js"></script>
7474
```
7575

76+
<<<<<<< HEAD
7677
Yllä, `/polku/tiedostoon/script.js` tarkoittaa absoluuttista tiedostopolkua skriptiin sivuston juuresta (root). Polun voi kirjoittaa myös nykyisen sivun suhteen. Esimerkiksi `src="script.js"` tarkoittaisi tiedostoa nimeltä `"script.js"` nykyisessä kansiossa.
78+
=======
79+
Here, `/path/to/script.js` is an absolute path to the script from the site root. One can also provide a relative path from the current page. For instance, `src="script.js"`, just like `src="./script.js"`, would mean a file `"script.js"` in the current folder.
80+
>>>>>>> 291b5c05b99452cf8a0d32bd32426926dbcc0ce0
7781
7882
Voimme kirjoittaa myös koko URL-osoitteen. Esimerkiksi:
7983

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,15 @@ Besides regular numbers, there are so-called "special numeric values" which also
4646
alert( "not a number" / 2 ); // NaN, such division is erroneous
4747
```
4848

49-
`NaN` is sticky. Any further operation on `NaN` returns `NaN`:
49+
`NaN` is sticky. Any further mathematical operation on `NaN` returns `NaN`:
5050

5151
```js run
52-
alert( "not a number" / 2 + 5 ); // NaN
52+
alert( NaN + 1 ); // NaN
53+
alert( 3 * NaN ); // NaN
54+
alert( "not a number" / 2 - 1 ); // NaN
5355
```
5456

55-
So, if there's a `NaN` somewhere in a mathematical expression, it propagates to the whole result.
57+
So, if there's a `NaN` somewhere in a mathematical expression, it propagates to the whole result (there's only one exception to that: `NaN ** 0` is `1`).
5658

5759
```smart header="Mathematical operations are safe"
5860
Doing maths is "safe" in JavaScript. We can do anything: divide by zero, treat non-numeric strings as numbers, etc.
@@ -213,14 +215,7 @@ The `symbol` type is used to create unique identifiers for objects. We have to m
213215

214216
The `typeof` operator returns the type of the argument. It's useful when we want to process values of different types differently or just want to do a quick check.
215217

216-
It supports two forms of syntax:
217-
218-
1. As an operator: `typeof x`.
219-
2. As a function: `typeof(x)`.
220-
221-
In other words, it works with parentheses or without them. The result is the same.
222-
223-
The call to `typeof x` returns a string with the type name:
218+
A call to `typeof x` returns a string with the type name:
224219

225220
```js
226221
typeof undefined // "undefined"
@@ -251,9 +246,19 @@ typeof alert // "function" (3)
251246
The last three lines may need additional explanation:
252247

253248
1. `Math` is a built-in object that provides mathematical operations. We will learn it in the chapter <info:number>. Here, it serves just as an example of an object.
254-
2. The result of `typeof null` is `"object"`. That's an officially recognized error in `typeof` behavior, coming from the early days of JavaScript and kept for compatibility. Definitely, `null` is not an object. It is a special value with a separate type of its own.
249+
2. The result of `typeof null` is `"object"`. That's an officially recognized error in `typeof`, coming from very early days of JavaScript and kept for compatibility. Definitely, `null` is not an object. It is a special value with a separate type of its own. The behavior of `typeof` is wrong here.
255250
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 also comes from the early days of JavaScript. Technically, such behavior isn't correct, but can be convenient in practice.
256251

252+
```smart header="The `typeof(x)` syntax"
253+
You may also come across another syntax: `typeof(x)`. It's the same as `typeof x`.
254+
255+
To put it clear: `typeof` is an operator, not a function. The parentheses here aren't a part of `typeof`. It's the kind of parentheses used for mathematical grouping.
256+
257+
Usually, such parentheses contain a mathematical expression, such as `(2 + 2)`, but here they contain only one argument `(x)`. Syntactically, they allow to avoid a space between the `typeof` operator and its argument, and some people like it.
258+
259+
Some people prefer `typeof(x)`, although the `typeof x` syntax is much more common.
260+
```
261+
257262
## Summary
258263
259264
There are 8 basic data types in JavaScript.
@@ -269,7 +274,7 @@ There are 8 basic data types in JavaScript.
269274
270275
The `typeof` operator allows us to see which type is stored in a variable.
271276
272-
- Two forms: `typeof x` or `typeof(x)`.
277+
- Usually used as `typeof x`, but `typeof(x)` is also possible.
273278
- Returns a string with the name of the type, like `"string"`.
274279
- For `null` returns `"object"` -- this is an error in the language, it's not actually an object.
275280

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ For example, `alert` automatically converts any value to a string to show it. Ma
77
There are also cases when we need to explicitly convert a value to the expected type.
88

99
```smart header="Not talking about objects yet"
10-
In this chapter, we won't cover objects. For now we'll just be talking about primitives.
10+
In this chapter, we won't cover objects. For now, we'll just be talking about primitives.
1111
1212
Later, after we learn about objects, in the chapter <info:object-toprimitive> we'll see how objects fit in.
1313
```

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,22 +194,22 @@ Here's an extract from the [precedence table](https://developer.mozilla.org/en-U
194194
| Precedence | Name | Sign |
195195
|------------|------|------|
196196
| ... | ... | ... |
197-
| 17 | unary plus | `+` |
198-
| 17 | unary negation | `-` |
199-
| 16 | exponentiation | `**` |
200-
| 15 | multiplication | `*` |
201-
| 15 | division | `/` |
202-
| 13 | addition | `+` |
203-
| 13 | subtraction | `-` |
197+
| 15 | unary plus | `+` |
198+
| 15 | unary negation | `-` |
199+
| 14 | exponentiation | `**` |
200+
| 13 | multiplication | `*` |
201+
| 13 | division | `/` |
202+
| 12 | addition | `+` |
203+
| 12 | subtraction | `-` |
204204
| ... | ... | ... |
205-
| 3 | assignment | `=` |
205+
| 2 | assignment | `=` |
206206
| ... | ... | ... |
207207

208-
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.
208+
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.
209209
210210
## Assignment
211211
212-
Let's note that an assignment `=` is also an operator. It is listed in the precedence table with the very low priority of `3`.
212+
Let's note that an assignment `=` is also an operator. It is listed in the precedence table with the very low priority of `2`.
213213

214214
That's why, when we assign a variable, like `x = 2 * 2 + 1`, the calculations are done first and then the `=` is evaluated, storing the result in `x`.
215215
@@ -437,7 +437,7 @@ The list of operators:
437437
- RIGHT SHIFT ( `>>` )
438438
- ZERO-FILL RIGHT SHIFT ( `>>>` )
439439
440-
These operators are used very rarely, when we need to fiddle with numbers on the very lowest (bitwise) level. We won't need these operators any time soon, as web development has little use of them, but in some special areas, such as cryptography, they are useful. You can read the [Bitwise Operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Bitwise) chapter on MDN when a need arises.
440+
These operators are used very rarely, when we need to fiddle with numbers on the very lowest (bitwise) level. We won't need these operators any time soon, as web development has little use of them, but in some special areas, such as cryptography, they are useful. You can read the [Bitwise Operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#bitwise_operators) chapter on MDN when a need arises.
441441

442442
## Comma
443443

1-js/02-first-steps/09-comparison/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ In JavaScript they are written like this:
77
- Greater/less than: <code>a &gt; b</code>, <code>a &lt; b</code>.
88
- Greater/less than or equals: <code>a &gt;= b</code>, <code>a &lt;= b</code>.
99
- Equals: `a == b`, please note the double equality sign `==` means the equality test, while a single one `a = b` means an assignment.
10-
- Not equals. In maths the notation is <code>&ne;</code>, but in JavaScript it's written as <code>a != b</code>.
10+
- Not equals: In maths the notation is <code>&ne;</code>, but in JavaScript it's written as <code>a != b</code>.
1111

1212
In this article we'll learn more about different types of comparisons, how JavaScript makes them, including important peculiarities.
1313

1-js/02-first-steps/11-logical-operators/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ This leads to some interesting usage compared to a "pure, classical, boolean-onl
123123

124124
It means that `||` processes its arguments until the first truthy value is reached, and then the value is returned immediately, without even touching the other argument.
125125

126-
That importance of this feature becomes obvious if an operand isn't just a value, but an expression with a side effect, such as a variable assignment or a function call.
126+
The importance of this feature becomes obvious if an operand isn't just a value, but an expression with a side effect, such as a variable assignment or a function call.
127127
128128
In the example below, only the second message is printed:
129129

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
The nullish coalescing operator is written as two question marks `??`.
66

7-
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`.
7+
As it treats `null` and `undefined` similarly, we'll use a special term here, in this article. For brevity, we'll say that a value is "defined" when it's neither `null` nor `undefined`.
88

99
The result of `a ?? b` is:
1010
- if `a` is defined, then `a`,
@@ -22,9 +22,9 @@ result = (a !== null && a !== undefined) ? a : b;
2222

2323
Now it should be absolutely clear what `??` does. Let's see where it helps.
2424

25-
The common use case for `??` is to provide a default value for a potentially undefined variable.
25+
The common use case for `??` is to provide a default value.
2626

27-
For example, here we show `user` if defined, otherwise `Anonymous`:
27+
For example, here we show `user` if its value isn't `null/undefined`, otherwise `Anonymous`:
2828

2929
```js run
3030
let user;
@@ -42,9 +42,9 @@ alert(user ?? "Anonymous"); // John (user defined)
4242
4343
We can also use a sequence of `??` to select the first value from a list that isn't `null/undefined`.
4444
45-
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.
45+
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 fill in the corresponding values.
4646
47-
We'd like to display the user name using one of these variables, or show "Anonymous" if all of them aren't defined.
47+
We'd like to display the user name using one of these variables, or show "Anonymous" if all of them are `null/undefined`.
4848
4949
Let's use the `??` operator for that:
5050
@@ -106,11 +106,11 @@ In practice, the zero height is often a valid value, that shouldn't be replaced
106106
107107
## Precedence
108108
109-
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`.
109+
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).
110110
111111
That means that, just like `||`, the nullish coalescing operator `??` is evaluated before `=` and `?`, but after most other operations, such as `+`, `*`.
112112
113-
So if we'd like to choose a value with `??` in an expression with other operators, consider adding parentheses:
113+
So we may need to add parentheses in expressions like this:
114114
115115
```js run
116116
let height = null;
@@ -128,7 +128,7 @@ Otherwise, if we omit parentheses, then as `*` has the higher precedence than `?
128128
// without parentheses
129129
let area = height ?? 100 * width ?? 50;
130130

131-
// ...works the same as this (probably not what we want):
131+
// ...works this way (not what we want):
132132
let area = height ?? (100 * width) ?? 50;
133133
```
134134
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.

0 commit comments

Comments
 (0)