Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1473 Updated chapter 3 - Contents section - Object key name types #1473

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

steevevadakkumchery
Copy link

Proposed a change in the text to say that when Symbols are used as keys in objects, it's not coerced into a string primitive.

var obj = {}
var firstSymbol = Symbol('hello');
var secondSymbol = Symbol('hello');

console.log(firstSymbol);           // Symbol(hello)
console.log(secondSymbol);     // Symbol(hello)

obj[firstSymbol] = 'first value';
obj[secondSymbol] = 'second value';

console.log(obj[firstSymbol]);             // first value
console.log(obj[secondSymbol]);       // second value

console.log(obj["Symbol(hello)"])      // undefined

Yes, I promise I've read the Contributions Guidelines (please feel free to remove this line).

Proposed a change in the text to say that when Symbols are used as keys in objects, it's not coerced into a string primitive.
```
var obj = {}
var firstSymbol = Symbol('hello');
var secondSymbol = Symbol('hello');

console.log(firstSymbol);           // Symbol(hello)
console.log(secondSymbol);     // Symbol(hello)

obj[firstSymbol] = 'first value';
obj[secondSymbol] = 'second value';

console.log(obj[firstSymbol]);             // first value
console.log(obj[secondSymbol]);       // second value

console.log(obj["Symbol(hello)"])      // undefined

```
@steevevadakkumchery steevevadakkumchery changed the title Updated chapter 3 - Contents section - Object key name types #1473 Updated chapter 3 - Contents section - Object key name types May 31, 2019
@@ -146,7 +146,7 @@ if (wantA) {
console.log( myObject[idx] ); // 2
```

In objects, property names are **always** strings. If you use any other value besides a `string` (primitive) as the property, it will first be converted to a string. This even includes numbers, which are commonly used as array indexes, so be careful not to confuse the use of numbers between objects and arrays.
In objects, property names are `strings` expect when using the primitive type `symbol`. If you use any other values besides `string` or `symbol` (primitives) as the property, it will first be converted to a string. This even includes numbers, which are commonly used as array indexes, so be careful not to confuse the use of numbers between objects and arrays.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typos. string except

Fixed typo in PR
@getify getify force-pushed the master branch 6 times, most recently from 5cb284a to 8af48e2 Compare August 28, 2019 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants