MapWithDefaultValue~MapWithDefaultValue(defaultValue)

new MapWithDefaultValue(defaultValue)

Map that has a default value specified in the constructor.

For the complete documentation of the Map see Map in the MDN web docs

Usage:

 let myMap = new MapWithDefaultValue(Infinity);
 const value = myMap.getWithDefault(key)

Note: This version is written specially for ES6 compiled into ES5. In non-compiled ES6 is the implementation far more elegant:

 export class MapWithDefaultValue extends Map {
     constructor(defaultValue) {
         super();

         this.default = defaultValue;
     }

     get(key) {
         if(this.has(key)) {
             return super.get(key);
         } else {
             return this.default;
         }
     }
 }```
Parameters:
Name Type Description
defaultValue any

default value that will be returned when the requested key is not found in the map