JavaScript MCQ Javascript Data Types MCQ Question #4904
Single Choice Difficult

QWhat is the result of the following code?
var map = new Map();
map.set(1, "one");
map.set(2, "two");
console.log(map.size);

ID: #4904 Javascript Data Types MCQ 350 views
Question Info
#4904Q ID
DifficultDifficulty
Javascript Data Types MCQTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A 1
  • B 2
  • C 6
  • D 8
Correct Answer

Explanation

The Map data type in JavaScript is a constructor that creates a new map object, which is a collection of key-value pairs.
The set method is used to add a new key-value pair to the map object.
In this case, two key-value pairs are added to the map object using the set method.
The size property is used to get the number of key-value pairs in the map object.
Since there are 2 key-value pairs in the map object, the size property will return 2.

Share This Question

Challenge a friend or share with your study group.