Bhumika Ojha | Javascript
Bhumika Ojha | Javascript

@ojhabhumika28

4 Tweets 6 reads Jun 03, 2023
🤔 Why do we need another collection to store key-value pairs when we already had objects in #javascript?
👇 Let's find out below
Problem#1 Object keys are implicitly converted to a string before performing the lookup. Therefore, obj[1] or obj["1"] gives the same result.
Problem#2 An object cannot be used as a key within another object. When an object is converted to a string, it becomes "[object Object].
Solution: Enter Map!
An incredible feature of Map is its ability to use any value as keys. It's not restricted to symbols or strings.
You can even use functions, objects, & dates as keys. Unlike regular objects, keys in Map won't be automatically converted to strings.
Get ready for JavaScript awesomeness! 🚀
🔁 Support me by liking, commenting, and sharing this thread.
💡 Follow me for mind-blowing #JavaScript tips and quizzes.
💪 Let's level up our skills together!

Loading suggestions...