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/04-object-basics/08-symbol/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
@@ -161,7 +161,7 @@ for (let key in user) alert(key); // name, age (no symbols)
161
161
alert( "Direct: "+ user[id] );
162
162
```
163
163
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.
165
165
166
166
In contrast, [Object.assign](mdn:js/Object/assign) copies both string and symbol properties:
Copy file name to clipboardExpand all lines: 1-js/05-data-types/12-json/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
@@ -27,7 +27,7 @@ Luckily, there's no need to write the code to handle all this. The task has been
27
27
28
28
## JSON.stringify
29
29
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.
Here the line `(*)` sets `animal` to be a prototype of `rabbit`.
57
+
Here the line `(*)` sets `animal` to be the prototype of `rabbit`.
58
58
59
59
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):
60
60
@@ -288,7 +288,7 @@ for(let prop in rabbit) alert(prop); // jumps, then eats
288
288
*/!*
289
289
```
290
290
291
-
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`.
291
+
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`.
292
292
293
293
So we can filter out inherited properties (or do something else with them):
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:
Copy file name to clipboardExpand all lines: 5-network/05-fetch-crossorigin/article.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -207,10 +207,11 @@ Some time ago no one could even imagine that a webpage could make such requests.
207
207
208
208
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.
209
209
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:
211
211
212
212
- `Access-Control-Request-Method` header has the method of the unsafe request.
213
213
- `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`)
214
215
215
216
If the server agrees to serve the requests, then it should respond with empty body, status 200 and headers:
Copy file name to clipboardExpand all lines: 6-data-storage/01-cookie/article.md
+16-12Lines changed: 16 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -96,38 +96,42 @@ Usually, we should set `path` to the root: `path=/` to make the cookie accessibl
96
96
97
97
A domain defines where the cookie is accessible. In practice though, there are limitations. We can't set any domain.
98
98
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.
100
102
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`.
102
106
103
107
```js
104
-
// at site.com
108
+
//if we set a cookie at site.com website...
105
109
document.cookie="user=John"
106
110
107
-
// at forum.site.com
111
+
//...we won't see it at forum.site.com
108
112
alert(document.cookie); // no user
109
113
```
110
114
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.
112
116
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.
114
118
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:
116
120
117
121
```js
118
122
// at site.com
119
123
// make the cookie accessible on any subdomain *.site.com:
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.
129
133
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.
131
135
132
136
## expires, max-age
133
137
@@ -180,7 +184,7 @@ With this option, if a cookie is set by `https://site.com`, then it doesn't appe
180
184
// assuming we're on https:// now
181
185
// set the cookie to be secure (only accessible over HTTPS)
182
186
document.cookie="user=John; secure";
183
-
```
187
+
```
184
188
185
189
## samesite
186
190
@@ -247,7 +251,7 @@ But anything more complicated, like a network request from another site or a for
247
251
248
252
If that's fine for you, then adding `samesite=lax` will probably not break the user experience and add protection.
0 commit comments