0

I'm a beginner and learning data structures and algorithms. I came to know a new data structure called Map.

I am confused why Map is created like this:

const countMap = new Map()

This is unlike other data structures like array where we simply write let array = [];

I searched about this Map syntax and found about constructors and instances etc

If I am correct then I heard about them in OOP. Now should I first learn OOP then continue DSA or what do you suggest?

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Hamza Baig
  • 11
  • 1
  • 1
    Your question is all over the place and not clear at all. I'd suggest you start by reading the [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) documentation for `Map()` and edit the question to give specific details of where you need assistance. – Rory McCrossan Jun 21 '23 at 10:01
  • 5
    Also, `let array = [];` is just syntactic sugar. It's still calling the Array constructor under the hood, eg: `let array = new Array();` – Rory McCrossan Jun 21 '23 at 10:03
  • 1
    i think knowing OOP is a must. it will help you easily understand other language, not just javascript. – Layhout Jun 21 '23 at 10:05
  • 2
    You can use `new Object()` and `new Array()` to create empty object and array as well. `{}` and `[]` are literal syntaxes for those. There is no literal to create an empty Map. – adiga Jun 21 '23 at 10:10
  • You do not need to know OOP to learn about DSA; but you do need to know _JavaScript_ in order to learn DSA _with JavaScript_ — and JavaScript happens to be an object-oriented language. If you were learning DSA with e.g. Scheme, then learning OOP would not be needed, but you would be expected to know about functional programming instead, since that is the paradigm used by Scheme. – Amadan Jun 21 '23 at 10:15
  • This is a common syntax in JavaScript and not something that just came up with `Map` For instance `new Date()` has been there since the early days of JavaScript. You'll just need to get an intro on JavaScript. Good luck. – trincot Jun 21 '23 at 10:45

0 Answers0