From c8de54970e181671f7b00259b8ec7249f216846d Mon Sep 17 00:00:00 2001 From: yoehae <210188757+yoehae@users.noreply.github.com> Date: Fri, 24 Apr 2026 18:44:22 +0200 Subject: [PATCH] fix(curriculum): correct WeakSet example with valid references (#66981) Co-authored-by: Jeevankumar S --- .../6733ab269b378bf724c9ac71.md | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/curriculum/challenges/english/blocks/lecture-working-with-maps-and-sets/6733ab269b378bf724c9ac71.md b/curriculum/challenges/english/blocks/lecture-working-with-maps-and-sets/6733ab269b378bf724c9ac71.md index 208e14571d2..7c72ca91645 100644 --- a/curriculum/challenges/english/blocks/lecture-working-with-maps-and-sets/6733ab269b378bf724c9ac71.md +++ b/curriculum/challenges/english/blocks/lecture-working-with-maps-and-sets/6733ab269b378bf724c9ac71.md @@ -218,13 +218,18 @@ const treeWeakSet = new WeakSet(); ```javascript const treeWeakSet = new WeakSet(); -treeWeakSet.add({ name: 'Baobab' }); -treeWeakSet.add({ name: 'Jackalberry' }); -treeWeakSet.add({ name: 'Mopane Tree' }); -treeWeakSet.add({ name: 'Breadfruit' }); +const baobab = { name: "Baobab" }; +const jackalberry = { name: "Jackalberry" }; +const mopaneTree = { name: "Mopane Tree" }; +const breadfruit = { name: "Breadfruit" }; -treeWeakSet.delete('Jackalberry'); -console.log(treeWeakSet.has('Jackalberry')); // false +treeWeakSet.add(baobab); +treeWeakSet.add(jackalberry); +treeWeakSet.add(mopaneTree); +treeWeakSet.add(breadfruit); + +treeWeakSet.delete(jackalberry); +console.log(treeWeakSet.has(jackalberry)); // false console.log(treeWeakSet); ``` @@ -233,17 +238,16 @@ In the output, the contents of the `WeakSet` appear like this: ```javascript /* -WeakSet {{…}, {…}, {…}, {…}} +WeakSet {{…}, {…}, {…}} [[Entries]] - No properties + 0: value: {name: 'Mopane Tree'} + 1: value: {name: 'Baobab'} + 2: value: {name: 'Breadfruit'} [[Prototype]]: WeakSet - . - . - . */ ``` -The contents appear empty because WeakSets are not iterable and do not expose their contents directly. +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. Don't forget that only symbols and objects with well-defined keys and values are supported. Adding a primitive, such as numbers or strings, will result in an error: