Skip to content

Conversation

wolfdaemon
Copy link
Contributor

This changes the "Reassigning object data type variables" with revised language and an extended example to explain the concept much more initially clear.

Because

This changes the "Reassigning object data type variables" with revised language and an extended example to explain the concept much more initially clear.

This PR

  • Changes the admonition titled "Reassigning object data type variables" to "Modifying the properties of an object vs. reassigning the object variables"
  • Changes the verbiage/example of the section to make things more clear, specifically:
    • Making a clear difference as to what a "mutation" vs changing the value of a primitive does
      • How the above affects variables that reference vs primitives that have a value on its own
      • Making a clear separating the between the variable name that references the object itself, vs the name/label/reference attached to it.

Pull Request Requirements

  • I have thoroughly read and understand The Odin Project curriculum contributing guide
  • The title of this PR follows the location of change: brief description of change format, e.g. Intro to HTML and CSS lesson: Fix link text
  • The Because section summarizes the reason for this PR
  • The This PR section has a bullet point list describing the changes in this PR
  • If this PR addresses an open issue, it is linked in the Issue section
  • If any lesson files are included in this PR, they have been previewed with the Markdown preview tool to ensure it is formatted correctly
  • If any lesson files are included in this PR, they follow the Layout Style Guide

This changes the "Reassigning object data type variables" with revised language and an extended example to explain the concept much more initially clear.
@github-actions github-actions bot added the Content: Foundations Involves the Foundations content label Jul 7, 2025
@rlmoser99 rlmoser99 requested review from a team and bycdiaz and removed request for a team July 8, 2025 01:39
@mao-sz mao-sz self-requested a review September 4, 2025 10:53
Copy link
Contributor

@mao-sz mao-sz left a comment

Choose a reason for hiding this comment

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

Many thanks, I think the idea behind this definitely makes a clearer distinction between mutation and reassignment. Just a couple of wording changes needed which are detailed below.

Could you also address the two linting errors regarding blank lines? And resolve the merge conflict too?

#### Reassigning object data type variables

While mutating the object we have a reference to affects all other variables that reference it, reassigning a variable does not change what the other variables refer to. For example:
#### Mutating the properties of an object vs. reassigning the object variables
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the new heading is a little verbose for a heading

Suggested change
#### Mutating the properties of an object vs. reassigning the object variables
#### Mutation vs. reassignment


// reassigning animal variable with a completely new object
animal = { species: "cat" };
// Mutating the properties of the object that both 'animal' and 'dog' reference
Copy link
Contributor

Choose a reason for hiding this comment

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

The object is being mutated, not the property (which is actually being reassigned)

Suggested change
// Mutating the properties of the object that both 'animal' and 'dog' reference
// Mutating the object that both 'animal' and 'dog' reference

console.log(animal); // { species: "bird" }
console.log(dog); // { species: "cat" }
```
In the first part, when we modify the species property of the object that both `animal` and `dog` reference, the change is reflected in both variables. In the second part, when we reassign the `animal` variable to a new object, the `dog` variable still references the original object, while `animal` now points to the new object.
Copy link
Contributor

@mao-sz mao-sz Sep 7, 2025

Choose a reason for hiding this comment

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

Fixing with the same as the previous review comment, and a small re-wording to accommodate that.

Suggested change
In the first part, when we modify the species property of the object that both `animal` and `dog` reference, the change is reflected in both variables. In the second part, when we reassign the `animal` variable to a new object, the `dog` variable still references the original object, while `animal` now points to the new object.
In the first part, there is only one object which is referenced by both `animal` and `dog`. When we mutate that object, the change is reflected in both variables. In the second part, when we reassign the `animal` variable to a new object; the `dog` variable still references the original object, while `animal` now points to the new object.


While mutating the object we have a reference to affects all other variables that reference it, reassigning a variable does not change what the other variables refer to. For example:
#### Mutating the properties of an object vs. reassigning the object variables
When you have multiple variables that reference the same object, mutating the properties of that object will affect all the variables that reference it. However, reassigning the object variable to a new object will only change the value of that specific variable, and will not affect the other variables that previously referenced the original object. For example:
Copy link
Contributor

@mao-sz mao-sz Sep 7, 2025

Choose a reason for hiding this comment

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

Just some small wording tweak given the rest of the review comments. Strength added to the mutate and reassign keywords.

Suggested change
When you have multiple variables that reference the same object, mutating the properties of that object will affect all the variables that reference it. However, reassigning the object variable to a new object will only change the value of that specific variable, and will not affect the other variables that previously referenced the original object. For example:
When multiple variables reference the same object, **mutating** that object will affect all the variables that reference it. However, **reassigning** a variable to a new object will only change the value of that specific variable, and will not automatically reassign any other variable that referenced the original object. For example:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content: Foundations Involves the Foundations content
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants