Skip to content

Commit

Permalink
Merge pull request #1 from yifeiyin/master
Browse files Browse the repository at this point in the history
Added a space after "for"
  • Loading branch information
yifeiyin committed Mar 16, 2019
2 parents f04f269 + 61ed067 commit 7f9851e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions 1-js/04-object-basics/01-object/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ To walk over all keys of an object, there exists a special form of the loop: `fo
The syntax:
```js
for(key in object) {
for (key in object) {
// executes the body for each key among object properties
}
```
Expand All @@ -353,7 +353,7 @@ let user = {
isAdmin: true
};

for(let key in user) {
for (let key in user) {
// keys
alert( key ); // name, age, isAdmin
// values for the keys
Expand All @@ -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.
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
Expand All @@ -384,7 +384,7 @@ let codes = {
};

*!*
for(let code in codes) {
for (let code in codes) {
alert(code); // 1, 41, 44, 49
}
*/!*
Expand Down Expand Up @@ -442,7 +442,7 @@ let codes = {
"+1": "USA"
};

for(let code in codes) {
for (let code in codes) {
alert( +code ); // 49, 41, 44, 1
}
```
Expand Down Expand Up @@ -720,7 +720,7 @@ To access a property, we can use:
Additional operators:
- To delete a property: `delete obj.prop`.
- 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.
Expand Down

0 comments on commit 7f9851e

Please sign in to comment.