From bcfd48e6b1382b977af3cc448a2d884e8512cc6d Mon Sep 17 00:00:00 2001 From: Ayush Kumar Himanshu Date: Mon, 10 Nov 2025 12:05:55 +0530 Subject: [PATCH 1/2] Update Map usage explanation in article.md Clarify the correct usage of Map methods and explain the implications of using map[key]. --- 1-js/05-data-types/07-map-set/article.md | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/1-js/05-data-types/07-map-set/article.md b/1-js/05-data-types/07-map-set/article.md index 37f5e48c2d..5fbdb621bc 100644 --- a/1-js/05-data-types/07-map-set/article.md +++ b/1-js/05-data-types/07-map-set/article.md @@ -41,12 +41,25 @@ alert( map.size ); // 3 As we can see, unlike objects, keys are not converted to strings. Any type of key is possible. -```smart header="`map[key]` isn't the right way to use a `Map`" -Although `map[key]` also works, e.g. we can set `map[key] = 2`, this is treating `map` as a plain JavaScript object, so it implies all corresponding limitations (only string/symbol keys and so on). +````smart header="`map[key]` isn’t the correct way to use a `Map`" +Although you can technically write `map[key] = value`, this does **not** store the data inside the `Map` collection. -So we should use `map` methods: `set`, `get` and so on. +Instead, it simply adds a regular property to the `Map` object itself—just like with plain JavaScript objects—and the key is always converted to a string. + +For example: + +```js run +let map = new Map(); +map["1"] = "test"; // adds a property, not a Map entry + +console.log(map.get("1")); // undefined +console.log(map["1"]); // "test" ``` +To properly store and retrieve data in a `Map`, always use its methods: +`map.set(key, value)` and `map.get(key)`. +```` + **Map can also use objects as keys.** For instance: From 71394cb5d2b9b6d0f37e903aa665b0bff5e9411f Mon Sep 17 00:00:00 2001 From: Ayush Kumar Himanshu Date: Thu, 13 Nov 2025 09:38:42 +0530 Subject: [PATCH 2/2] Update 1-js/05-data-types/07-map-set/article.md Accepted the changes from the review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- 1-js/05-data-types/07-map-set/article.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/05-data-types/07-map-set/article.md b/1-js/05-data-types/07-map-set/article.md index 5fbdb621bc..66fa5b6616 100644 --- a/1-js/05-data-types/07-map-set/article.md +++ b/1-js/05-data-types/07-map-set/article.md @@ -52,8 +52,8 @@ For example: let map = new Map(); map["1"] = "test"; // adds a property, not a Map entry -console.log(map.get("1")); // undefined -console.log(map["1"]); // "test" +alert(map.get("1")); // undefined +alert(map["1"]); // "test" ``` To properly store and retrieve data in a `Map`, always use its methods: