JS Startup

Challenges, Tips & Tricks & Tutorials

JavaScript Quiz – Find out the size of a javascript map object

JavaScript Quiz – Find out the size of a javascript map object

JavaScript Map Object –

Javascript map object is a collection of keyed data items, just like an Object. But the main difference is that Map allows keys of any type.

Question –

Here, we use a map object a new Map() and assign it to the maps variable created with let.

After it we use a set method of map object, which allow to save value in maps.

Then we set 3 value in maps object which are “JS”, “Startup”, “JS”

Now, you need to find out. What should be the size of maps object after setting 3 value.

Answer – 2

Click To Run Code

Explanation –

We know new Map() is like an object which allows storing the value of different-different data type and keys also.

In the above javascript quiz, we use a map object with a set method which is used to store value.

So, we use set method 3 times with maps object but “JS” is twice and the new Map() only store unique values. So, “JS” is store only once.

I think you know the answer know.

Check out our other javascript quiz – 

  1. FIND OUT THE OUTPUT OF A REVERSE STRING
  2. DOES NESTED ARRAY REFERENCE REMOVED BY SPREAD SYNTAX

Conclusion –

To participate in more javascript challenges, make sure to join our jsstartup newsletter. So, you can able to participate in our daily challenges.

And last but not the least, don’t forget to like, comment and share. It gives us a morale boost to remain to continue. Also, join our Facebook Page

If you have any question, please feel free to ask me in the comment section and also let me know if you have any suggestions. As suggestions are always welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top
0 Shares
Share via
Copy link