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
Now everything is fine. Please note that the string inside the brackets is properly quoted (any type of quotes will do).
123
+
Now everything is fine. Please note that the string inside the brackets is properly quoted (any type of quote will do).
124
124
125
125
Square brackets also provide a way to obtain the property name as the result of any expression -- as opposed to a literal string -- like from a variable as follows:
126
126
@@ -201,13 +201,13 @@ let bag = {
201
201
};
202
202
```
203
203
204
-
Square brackets are much more powerful than the dot notation. They allow any property names and variables. But they are also more cumbersome to write.
204
+
Square brackets are much more powerful than dot notation. They allow any property names and variables. But they are also more cumbersome to write.
205
205
206
206
So most of the time, when property names are known and simple, the dot is used. And if we need something more complex, then we switch to square brackets.
207
207
208
208
## Property value shorthand
209
209
210
-
In real code we often use existing variables as values for property names.
210
+
In real code, we often use existing variables as values for property names.
211
211
212
212
For instance:
213
213
@@ -252,7 +252,7 @@ let user = {
252
252
253
253
## Property names limitations
254
254
255
-
As we already know, a variable cannot have a name equal to one of language-reserved words like "for", "let", "return" etc.
255
+
As we already know, a variable cannot have a name equal to one of the language-reserved words like "for", "let", "return" etc.
256
256
257
257
But for an object property, there's no such restriction:
258
258
@@ -325,7 +325,7 @@ alert( "blabla" in user ); // false, user.blabla doesn't exist
325
325
326
326
Please note that on the left side of `in` there must be a *property name*. That's usually a quoted string.
327
327
328
-
If we omit quotes, that means a variable, it should contain the actual name to be tested. For instance:
328
+
If we omit quotes, that means a variable should contain the actual name to be tested. For instance:
329
329
330
330
```js run
331
331
let user = { age:30 };
@@ -412,7 +412,7 @@ for (let code in codes) {
412
412
*/!*
413
413
```
414
414
415
-
The object may be used to suggest a list of options to the user. If we're making a site mainly for German audience then we probably want `49` to be the first.
415
+
The object may be used to suggest a list of options to the user. If we're making a site mainly for a German audience then we probably want `49` to be the first.
416
416
417
417
But if we run the code, we see a totally different picture:
418
418
@@ -481,7 +481,7 @@ They store properties (key-value pairs), where:
481
481
482
482
To access a property, we can use:
483
483
- The dot notation: `obj.property`.
484
-
- Square brackets notation `obj["property"]`. Square brackets allow to take the key from a variable, like `obj[varWithKey]`.
484
+
- Square brackets notation `obj["property"]`. Square brackets allow taking the key from a variable, like `obj[varWithKey]`.
0 commit comments