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

Clarify some things in Objects intro #3721

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions 1-js/04-object-basics/01-object/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ In contrast, objects are used to store keyed collections of various data and mor

An object can be created with 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.

We can imagine an object as a cabinet with signed files. Every piece of data is stored in its file by the key. It's easy to find a file by its name or add/remove a file.
We can imagine an object as a cabinet with labeled folders. Every piece of data is stored in its folder by the key. It's easy to find a folder by its name or add/remove a folder.
Copy link
Contributor

@shallow-beach shallow-beach Aug 24, 2024

Choose a reason for hiding this comment

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

file is clear IMO, see File cabinet wiki. i don't think folders is less clear though


![](object.svg)

Expand Down Expand Up @@ -40,11 +40,11 @@ In the `user` object, there are two properties:
1. The first property has the name `"name"` and the value `"John"`.
2. The second one has the name `"age"` and the value `30`.

The resulting `user` object can be imagined as a cabinet with two signed files labeled "name" and "age".
The resulting `user` object can be imagined as a cabinet with two folders labeled "name" and "age".

![user object](object-user.svg)

We can add, remove and read files from it at any time.
We can add, remove and read folders from it at any time.

Property values are accessible using the dot notation:

Expand Down Expand Up @@ -101,7 +101,7 @@ For multiword properties, the dot access doesn't work:
user.likes birds = true
```

JavaScript doesn't understand that. It thinks that we address `user.likes`, and then gives a syntax error when comes across unexpected `birds`.
JavaScript doesn't understand that. It thinks that we're referring to `user.likes`, and then gives a syntax error when it comes across the unexpected `birds`.
Copy link
Contributor

Choose a reason for hiding this comment

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

How about 'accessing' (used in MDN):

JavaScript doesn't understand that. It thinks that we're accessing user.likes, and then gives a syntax error when it comes across the unexpected birds.


The dot requires the key to be a valid variable identifier. That implies: contains no spaces, doesn't start with a digit and doesn't include special characters (`$` and `_` are allowed).

Expand Down Expand Up @@ -161,7 +161,7 @@ alert( user.key ) // undefined

### Computed properties

We can use square brackets in an object literal, when creating an object. That's called *computed properties*.
If you want to be flexible about naming your properties, you can use something called *computed properties*.
Copy link
Contributor

Choose a reason for hiding this comment

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

disagree, Line 164 is clarifying that square brackets are computed properties


For instance:

Expand Down