Skip to content

Prevent Object Mutation with Object.freeze: Conflicting info #43330

Closed

Description

@amberream

Affected page

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/prevent-object-mutation

Expected behavior

At the top, the challenge says, " Any attempt at changing the object will be rejected without an error." A few lines later it says, "The obj.review and obj.newProp assignments will result in errors".

This seems to be conflicting information - will there be an error or not? Maybe the 2nd part should say "The obj.review and obj.newProp assignments will be rejected".

Screenshots

image

Activity

  1. added
    scope: curriculum
    status: waiting triage
    on Aug 28, 2021
  2. amberream commented on Aug 28, 2021

    @amberream
    Author

    Oddly, when I run the tests I can see an error in the log:
    [TypeError: Cannot assign to read only property 'PI' of object '#']

    But when I run the same code in jsFiddle there is no error in the console.

    Update: When I add "use strict" in jsFiddle I get an error. This challenge should definitely mention that you only get an error in strict mode!

    One of the previous challenges about "let" and "const" mention strict mode briefly, but it might be good to explain strict mode more. This page was helpful: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode

  3. naomi-lgbt commented on Sep 1, 2021

    @naomi-lgbt
    Member

    I do agree that some clarification here would be beneficial.

    Possibly changing that first line to `Any attempt at changing the object will be rejected, with an error thrown if the script is running in strict mode.

    And the second line being The obj.review and obj.newProp assignments will result in errors, because our editor runs in strict mode by default, and the console will...

    Thoughts?

  4. added
    status: discussing
    and removed
    status: waiting triage
    on Sep 1, 2021
  5. Sembauke commented on Sep 5, 2021

    @Sembauke
    Member

    That seems like a good solution Nich, I'll put a help wanted label on it!

  6. added
    help wanted
    and removed
    status: discussing
    on Sep 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedscope: curriculum

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions