I am printing a Map object before and after setting the map value. Before setting the map value, the map size is 0, which is correct, but the entries size is already 1.
script.js
const map = new Map();
console.log('Before calling map.set');
console.log(map);
console.log('After calling map.set');
map.set('key1', 'value1');
console.log(map);
Console
Before calling map.set
Map(0) {size: 0}
[[Entries]]
0: {"key1" => "value1"}
size: 1
[[Prototype]]: Map
After calling map.set
Map(1) {'key1' => 'value1'}
[[Entries]]
0: {"key1" => "value1"}
size: 1
[[Prototype]]: Map
I tried to map.get('key1')
before calling map.set
and it returns undefined correctly.
In the first console.log
, I was expecting the entries size to be 0, similar to the map size as I have not called map.set('key1', 'value1')
. I do not understand why the entries size is already set before the map value is set.