Am trying to understand Maps objects in javascript, and how to use them inside an application, but there's something that i cant understand and it leads me to this question, here's my example
const myMap = new Map();
myMap.set('Name', 'John Doe')
.set(1, function sayHello(user){ console.log(`Hello ${user}`)})
myMap.get('Name'); // output John Doe
myMap.get(1); // output [function: sayHello]
as you see above i can set a function inside the Map
- how can i use that function?
- what's the point of setting a function in a Map?
- are there any use cases?
I'm so confused, i will appreciate any explanation
myMap.get(1)('Bob');are there any use cases?many, yes. eg. a map with function could be used instead of a massiveifelseblocks etc.