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/2-first-steps/07-types/article.md
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -176,12 +176,12 @@ All other types are called "primitive", because their values can contain only a
176
176
177
177
In contrast, objects are used to store *keyed collections* of various data and more complex entities. In programming that's sometimes called an "associative array" or a "hash".
178
178
179
-
An object is defined with the figure brackets `{…}` with an optional list of *properties*. A property is a "key: value" pairs, where `key` is a string (also called a "property name"), and `value` can be anything.
179
+
An object is defined with the figure brackets `{…}` with an optional list of *properties*. A property is a "key: value" pair, where `key` is a string (also called a "property name"), and `value` can be anything.
180
180
181
-
For instance, here we create a `user` object with two properties:
181
+
For instance, here we create an object `user` with two properties:
182
182
183
183
```js
184
-
let user = { // an object
184
+
let user = {
185
185
name:"John", // key "name", value "John"
186
186
age:30// key "age", value 30
187
187
};
@@ -207,23 +207,23 @@ user.isAdmin = true;
207
207
208
208

209
209
210
-
...Or remove it with the help of `delete` operator:
210
+
...Or remove the `age` property with the help of `delete` operator:
211
211
212
212
```js
213
213
deleteuser.age;
214
214
```
215
215
216
216

217
217
218
-
Technically, the key may be any string, even with multiple words, for instance `"hello world"`, or even a sentence like `"likes to swim?"`.
218
+
Technically, we can name the property using any string, like `"hello world"`, or even a sentence like `"likes to swim?"`. And sometimes that's handy.
219
219
220
-
To work with such keys, there exists another way to access them, because the dot notation doesn't work:
220
+
But to work with complex keys, there's another way to access them, because the dot notation stops working:
221
221
222
222
```js run
223
223
user.likes to swim?=true; // syntax error!
224
224
```
225
225
226
-
The dot assumes that the key is a valid variable identifier (no spaces and other limitations).
226
+
That's because the dot only supports keys that are valid variable identifiers (no spaces and other limitations).
227
227
228
228
There's a more powerful "square bracket notation" that works with any string:
229
229
@@ -240,9 +240,9 @@ alert(user["likes to swim?"]); // true
240
240
delete user["likes to swim?"];
241
241
```
242
242
243
-
Now everything is fine. Please note that the string must be properly quoted (any type of quotes will do).
243
+
Now everything is fine. Please note that the string is properly quoted (any type of quotes will do).
244
244
245
-
Square brackets are also the way to access a property by the name from the variable:
245
+
Square brackets are also provide a way to access a property by the name from the variable:
246
246
247
247
```js
248
248
let key ="likes to swim?";
@@ -251,7 +251,7 @@ let key = "likes to swim?";
251
251
user[key] =true;
252
252
```
253
253
254
-
Here, the variable `key` is probably evaluated or calculated at run-time. And then we use it to access the property. That gives us a great deal of flexibility. The dot notation cannot be used the similar way.
254
+
Here, the variable `key` is may be evaluated or calculated at run-time. And then we use it to access the property. That gives us a great deal of flexibility. The dot notation cannot be used in similar way.
255
255
256
256
So, most of time, the dot notation is used to access known and simple object properties, but when we need something more complex, then we use square brackets.
257
257
@@ -268,15 +268,15 @@ They serve as a basis for many other, more specialized kinds of objects:
268
268
269
269
These more advanced objects do not have types of their own, but belong to a single "object" data type. And they extend it in various ways. Of course we'll see how they do it.
270
270
271
-
Objects in JavaScript are very powerful. Here we've just started to get the basics of the topic that is really huge. Now we can create plain objects and add/remove properties from them. But we'll be closely working with objects and learning more about them in further parts of the tutorial.
271
+
Objects in JavaScript are very powerful. Here we've just started to get the basics of the topic that is really huge. Now we can create plain objects and add/remove properties from them. But we'll be consistently returning to objects and learn much more about them in further parts of the tutorial.
272
272
273
273
## Arrays
274
274
275
275
As we’ve just seen, objects in Javascript store arbitrary keyed values.
276
276
277
277
But quite often we find that we need an *ordered collection*, where we have a 1st, a 2nd, a 3rd element and so on.
278
278
279
-
For example, we need that to store a list of something: users, goods, HTML elements etc. Plain objects do not provide ways to set the order of elements. We can't directly access the n-th element in an object by its number. Also we can’t insert a new property between the existing ones. Objects are just not meant for such use.
279
+
For example, we need that to store a list of something: users, goods, HTML elements etc. Plain objects do not provide ways to set the order of elements. We can't directly access the n-th property of an object by its number. Also we can’t insert a new property "between" the existing ones. Objects are just not meant for such use.
280
280
281
281
There exists a special data structure named "an array", to store ordered collections.
282
282
@@ -318,7 +318,7 @@ A value of this type can be created using `Symbol(name)`:
318
318
let id =Symbol("id");
319
319
```
320
320
321
-
If you used Ruby language (or few others that have symbols too), then you may have heard a thing or two about symbols already. But stay tuned. Symbols in JavaScript are different. Please don't get trapped by the same word.
321
+
If you used Ruby language (or few others that have symbols too), then you may feel proficient about symbols already. But stay tuned. Symbols in JavaScript are different. Please don't get trapped by the same word.
322
322
323
323
`Symbol` is a special primitive type used for identifiers, which are guaranteed to be unique. So, even if we create many symbols with the same name, they are still unique, and not equal:
324
324
@@ -327,7 +327,7 @@ let id1 = Symbol("id");
327
327
let id2 =Symbol("id");
328
328
329
329
*!*
330
-
alert(id1 == id2); // false
330
+
alert(id1 == id2); // false (!)
331
331
*/!*
332
332
```
333
333
@@ -347,7 +347,7 @@ user.id = 123;
347
347
alert( user.id ); // 123
348
348
```
349
349
350
-
Now let's imagine that another script wants to work with that object, and it also would like to store an identifier in the object, for its own purposes. The script is written by another person, so the scripts are completely unaware for each other.
350
+
Now let's imagine that another script wants to work with that object, and it also would like to store an identifier in the object, for its own purposes. The script is written by *another person*, so the scripts are completely unaware for each other.
351
351
352
352
...But if it tries to make use of the same `"id"` key, then it would occasionally overwrite our id. That's the conflict.
Copy file name to clipboardExpand all lines: 1-js/2-first-steps/12-uibasic/article.md
+1-7Lines changed: 1 addition & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,13 +36,7 @@ It shows a modal window with the given `title`, a field for text, initially fill
36
36
37
37
The visitor may type something in the field and press OK. Or he can cancel the input by pressing a CANCEL button or the `key:Esc` key.
38
38
39
-
The call to `prompt` returns the text from the field or `null` if te input is canceled.
40
-
41
-
```warn header="Safari does not return `null`"
42
-
Safari returns an empty string instead of `null` on cancellation. So we can't be sure whether the user actually entered an empty line or he cancelled the input.
43
-
44
-
A compatible practice is to treat both an empty line and `null` the same, as a cancellation.
45
-
```
39
+
The call to `prompt` returns the text from the field or `null` if the input is canceled.
0 commit comments