Skip to content

Commit 46e1ae9

Browse files
committed
Merge branch 'master' of github.com:javascript-tutorial/en.javascript.info into sync-3c934b5a
2 parents 728c1d2 + 3c934b5 commit 46e1ae9

File tree

7 files changed

+24
-19
lines changed

7 files changed

+24
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ In more advanced situations, that we'll come across later, a function may be cre
3434

3535
## Function is a value
3636

37-
Let's reiterate: no matter how the function is created, a function is a value. Both examples above store a function is `sayHi` variable.
37+
Let's reiterate: no matter how the function is created, a function is a value. Both examples above store a function in the `sayHi` variable.
3838

3939
We can even print out that value using `alert`:
4040

1-js/04-object-basics/08-symbol/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ for (let key in user) alert(key); // name, age (no symbols)
161161
alert( "Direct: " + user[id] );
162162
```
163163

164-
[Object.keys(user)](mdn:js/Object/keys) also ignores them. That's a part of the general "hiding symbolic properties" principle. If another script or a library loops over our object, it won't unexpectedly access a symbolic property.
164+
[Object.keys(user)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys) also ignores them. That's a part of the general "hiding symbolic properties" principle. If another script or a library loops over our object, it won't unexpectedly access a symbolic property.
165165

166166
In contrast, [Object.assign](mdn:js/Object/assign) copies both string and symbol properties:
167167

1-js/05-data-types/12-json/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Luckily, there's no need to write the code to handle all this. The task has been
2727

2828
## JSON.stringify
2929

30-
The [JSON](http://en.wikipedia.org/wiki/JSON) (JavaScript Object Notation) is a general format to represent values and objects. It is described as in [RFC 4627](http://tools.ietf.org/html/rfc4627) standard. Initially it was made for JavaScript, but many other languages have libraries to handle it as well. So it's easy to use JSON for data exchange when the client uses JavaScript and the server is written on Ruby/PHP/Java/Whatever.
30+
The [JSON](http://en.wikipedia.org/wiki/JSON) (JavaScript Object Notation) is a general format to represent values and objects. It is described as in [RFC 4627](https://tools.ietf.org/html/rfc4627) standard. Initially it was made for JavaScript, but many other languages have libraries to handle it as well. So it's easy to use JSON for data exchange when the client uses JavaScript and the server is written on Ruby/PHP/Java/Whatever.
3131

3232
JavaScript provides methods:
3333

1-js/08-prototypes/01-prototype-inheritance/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ alert( rabbit.eats ); // true (**)
5454
alert( rabbit.jumps ); // true
5555
```
5656

57-
Here the line `(*)` sets `animal` to be a prototype of `rabbit`.
57+
Here the line `(*)` sets `animal` to be the prototype of `rabbit`.
5858

5959
Then, when `alert` tries to read property `rabbit.eats` `(**)`, it's not in `rabbit`, so JavaScript follows the `[[Prototype]]` reference and finds it in `animal` (look from the bottom up):
6060

@@ -287,7 +287,7 @@ for(let prop in rabbit) alert(prop); // jumps, then eats
287287
*/!*
288288
```
289289

290-
If that's not what we want, and we'd like to exclude inherited properties, there's a built-in method [obj.hasOwnProperty(key)](mdn:js/Object/hasOwnProperty): it returns `true` if `obj` has its own (not inherited) property named `key`.
290+
If that's not what we want, and we'd like to exclude inherited properties, there's a built-in method [obj.hasOwnProperty(key)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty): it returns `true` if `obj` has its own (not inherited) property named `key`.
291291

292292
So we can filter out inherited properties (or do something else with them):
293293

1-js/09-classes/01-class/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ alert(Object.getOwnPropertyNames(User.prototype)); // constructor, sayHi
118118

119119
## Not just a syntactic sugar
120120

121-
Sometimes people say that `class` is a "syntactic sugar" (syntax that is designed to make things easier to read, but doesn't introduce anything new), because we could actually declare the same without `class` keyword at all:
121+
Sometimes people say that `class` is a "syntactic sugar" (syntax that is designed to make things easier to read, but doesn't introduce anything new), because we could actually declare the same thing without using the `class` keyword at all:
122122

123123
```js run
124124
// rewriting class User in pure functions

5-network/05-fetch-crossorigin/article.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,11 @@ Some time ago no one could even imagine that a webpage could make such requests.
207207

208208
So, to avoid misunderstandings, any "unsafe" request -- that couldn't be done in the old times, the browser does not make such requests right away. First, it sends a preliminary, so-called "preflight" request, to ask for permission.
209209
210-
A preflight request uses the method `OPTIONS`, no body and two headers:
210+
A preflight request uses the method `OPTIONS`, no body and three headers:
211211
212212
- `Access-Control-Request-Method` header has the method of the unsafe request.
213213
- `Access-Control-Request-Headers` header provides a comma-separated list of its unsafe HTTP-headers.
214+
- `Origin` header tells from where the request came. (such as `https://javascript.info`)
214215
215216
If the server agrees to serve the requests, then it should respond with empty body, status 200 and headers:
216217

6-data-storage/01-cookie/article.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,38 +96,42 @@ Usually, we should set `path` to the root: `path=/` to make the cookie accessibl
9696

9797
A domain defines where the cookie is accessible. In practice though, there are limitations. We can't set any domain.
9898

99-
By default, a cookie is accessible only at the domain that set it. So, if the cookie was set by `site.com`, we won't get it at `other.com`.
99+
**There's no way to let a cookie be accessible from another 2nd-level domain, so `other.com` will never receive a cookie set at `site.com`.**
100+
101+
It's a safety restriction, to allow us to store sensitive data in cookies that should be available only on one site.
100102

101-
...But what's more tricky, we also won't get the cookie at a subdomain `forum.site.com`!
103+
By default, a cookie is accessible only at the domain that set it.
104+
105+
Please note, by default a cookie is also not shared to a subdomain as well, such as `forum.site.com`.
102106

103107
```js
104-
// at site.com
108+
// if we set a cookie at site.com website...
105109
document.cookie = "user=John"
106110

107-
// at forum.site.com
111+
// ...we won't see it at forum.site.com
108112
alert(document.cookie); // no user
109113
```
110114

111-
**There's no way to let a cookie be accessible from another 2nd-level domain, so `other.com` will never receive a cookie set at `site.com`.**
115+
...But this can be changed. If we'd like to allow subdomains like `forum.site.com` to get a cookie set at `site.com`, that's possible.
112116

113-
It's a safety restriction, to allow us to store sensitive data in cookies, that should be available only on one site.
117+
For that to happen, when setting a cookie at `site.com`, we should explicitly set the `domain` option to the root domain: `domain=site.com`. Then all subdomains will see such cookie.
114118

115-
...But if we'd like to allow subdomains like `forum.site.com` to get a cookie, that's possible. When setting a cookie at `site.com`, we should explicitly set the `domain` option to the root domain: `domain=site.com`:
119+
For example:
116120

117121
```js
118122
// at site.com
119123
// make the cookie accessible on any subdomain *.site.com:
120-
document.cookie = "user=John; domain=site.com"
124+
document.cookie = "user=John; *!*domain=site.com*/!*"
121125

122126
// later
123127

124128
// at forum.site.com
125129
alert(document.cookie); // has cookie user=John
126130
```
127131

128-
For historical reasons, `domain=.site.com` (a dot before `site.com`) also works the same way, allowing access to the cookie from subdomains. That's an old notation and should be used if we need to support very old browsers.
132+
For historical reasons, `domain=.site.com` (with a dot before `site.com`) also works the same way, allowing access to the cookie from subdomains. That's an old notation and should be used if we need to support very old browsers.
129133

130-
So, the `domain` option allows to make a cookie accessible at subdomains.
134+
To summarize, the `domain` option allows to make a cookie accessible at subdomains.
131135

132136
## expires, max-age
133137

@@ -180,7 +184,7 @@ With this option, if a cookie is set by `https://site.com`, then it doesn't appe
180184
// assuming we're on https:// now
181185
// set the cookie to be secure (only accessible over HTTPS)
182186
document.cookie = "user=John; secure";
183-
```
187+
```
184188

185189
## samesite
186190

@@ -247,7 +251,7 @@ But anything more complicated, like a network request from another site or a for
247251

248252
If that's fine for you, then adding `samesite=lax` will probably not break the user experience and add protection.
249253

250-
Overall, `samesite` is a great option.
254+
Overall, `samesite` is a great option.
251255

252256
There's a drawback:
253257

0 commit comments

Comments
 (0)