fix(curriculum): correct WeakSet example with valid references by yoehae · Pull Request #66981 · freeCodeCamp/freeCodeCamp · GitHub
Skip to content

fix(curriculum): correct WeakSet example with valid references#66981

Open
yoehae wants to merge 3 commits intofreeCodeCamp:mainfrom
yoehae:fix/weakset-example-references
Open

fix(curriculum): correct WeakSet example with valid references#66981
yoehae wants to merge 3 commits intofreeCodeCamp:mainfrom
yoehae:fix/weakset-example-references

Conversation

@yoehae
Copy link
Copy Markdown

@yoehae yoehae commented Apr 17, 2026

Checklist:

Closes #66982

Update the WeakSet example to pass object variables to treeWeakSet.add() instead of object literals, and to pass an object variable to treeWeakSet.has() instead of a string.

  1. Passing an object literal directly to .add() leaves no variable bound to the added object, so there is no way to reference it later. A subsequent .has() call with a literal that looks identical will still return false, because each literal evaluates to a distinct object and WeakSet compares entries by reference identity.
  2. Separately, because WeakSet holds only weak references, an object added via a bare literal has no remaining strong reference once the statement completes, making it eligible for garbage collection and liable to disappear from the set before any later check.
  3. Passing a string to .has() always returns false, because WeakSet can only store objects. Strings are not valid entries.

Note: resubmitting after a previous web-UI PR was deprioritized. Verified locally in a Codespace with FCC_BLOCK='lecture-working-with-maps-and-sets' pnpm run develop, confirmed the corrected code renders on the lesson page.

Opened a tracking issue at #66982 and linked it in the description. Will wait for triage before expecting review.

@yoehae yoehae requested review from a team as code owners April 17, 2026 19:01
@github-actions github-actions Bot added scope: curriculum Lessons, Challenges, Projects and other Curricular Content in curriculum directory. deprioritized PR reviews are deprioritized; lacks productive input and ignores codebase best practices. labels Apr 17, 2026
@github-actions

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor

@majestic-owl448 majestic-owl448 left a comment

Choose a reason for hiding this comment

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

please update the output snippet below to be

WeakSet {{}, {}, {}}
  [[Entries]]
    0: value: {name: 'Mopane Tree'}
    1: value: {name: 'Baobab'}
    2: value: {name: 'Breadfruit'}
  [[Prototype]]: WeakSet

and the paragraph "The contents appear empty because WeakSets are not iterable and do not expose their contents directly."

to

The contents are visible here because the object variables still hold strong references, keeping those objects in memory. Keep in mind that WeakSets are not iterable, so there is no way to loop over their entries or access them programmatically. What you see in the output is only a debugging aid.

@Jeevankumar-s Jeevankumar-s added status: waiting update Is awaiting update, after feedback or request for changes and removed status: blocked In a transient & temporary hold. labels Apr 20, 2026
@yoehae
Copy link
Copy Markdown
Author

yoehae commented Apr 20, 2026

@Jeevankumar-s Jeevankumar-s added status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. js v9 cert This is for the JS V9 certification. and removed status: waiting update Is awaiting update, after feedback or request for changes deprioritized PR reviews are deprioritized; lacks productive input and ignores codebase best practices. labels Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

js v9 cert This is for the JS V9 certification. scope: curriculum Lessons, Challenges, Projects and other Curricular Content in curriculum directory. status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inaccurate WeakSet example in "What are Sets in JavaScript and how does it differ from WeakSets" lesson

3 participants