Added a space after "for"

For consistency with the rest of the document and the "coding style" chapter
This commit is contained in:
Yifei Yin 2019-03-15 21:41:40 -04:00 committed by GitHub
parent 364e707b2a
commit 61ed0672b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -339,7 +339,7 @@ To walk over all keys of an object, there exists a special form of the loop: `fo
The syntax: The syntax:
```js ```js
for(key in object) { for (key in object) {
// executes the body for each key among object properties // executes the body for each key among object properties
} }
``` ```
@ -353,7 +353,7 @@ let user = {
isAdmin: true isAdmin: true
}; };
for(let key in user) { for (let key in user) {
// keys // keys
alert( key ); // name, age, isAdmin alert( key ); // name, age, isAdmin
// values for the keys // values for the keys
@ -363,7 +363,7 @@ for(let key in user) {
Note that all "for" constructs allow us to declare the looping variable inside the loop, like `let key` here. Note that all "for" constructs allow us to declare the looping variable inside the loop, like `let key` here.
Also, we could use another variable name here instead of `key`. For instance, `"for(let prop in obj)"` is also widely used. Also, we could use another variable name here instead of `key`. For instance, `"for (let prop in obj)"` is also widely used.
### Ordered like an object ### Ordered like an object
@ -384,7 +384,7 @@ let codes = {
}; };
*!* *!*
for(let code in codes) { for (let code in codes) {
alert(code); // 1, 41, 44, 49 alert(code); // 1, 41, 44, 49
} }
*/!* */!*
@ -442,7 +442,7 @@ let codes = {
"+1": "USA" "+1": "USA"
}; };
for(let code in codes) { for (let code in codes) {
alert( +code ); // 49, 41, 44, 1 alert( +code ); // 49, 41, 44, 1
} }
``` ```
@ -720,7 +720,7 @@ To access a property, we can use:
Additional operators: Additional operators:
- To delete a property: `delete obj.prop`. - To delete a property: `delete obj.prop`.
- To check if a property with the given key exists: `"key" in obj`. - To check if a property with the given key exists: `"key" in obj`.
- To iterate over an object: `for(let key in obj)` loop. - To iterate over an object: `for (let key in obj)` loop.
Objects are assigned and copied by reference. In other words, a variable stores not the "object value", but a "reference" (address in memory) for the value. So copying such a variable or passing it as a function argument copies that reference, not the object. All operations via copied references (like adding/removing properties) are performed on the same single object. Objects are assigned and copied by reference. In other words, a variable stores not the "object value", but a "reference" (address in memory) for the value. So copying such a variable or passing it as a function argument copies that reference, not the object. All operations via copied references (like adding/removing properties) are performed on the same single object.