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
338k41 gold badges322 silver badges353 bronze badges
asked Jun 21, 2023 at 10:00
6
  • 1
    Your question is all over the place and not clear at all. I'd suggest you start by reading the MDN documentation for Map() and edit the question to give specific details of where you need assistance. Commented Jun 21, 2023 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(); Commented Jun 21, 2023 at 10:03
  • 1
    i think knowing OOP is a must. it will help you easily understand other language, not just javascript. Commented Jun 21, 2023 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. Commented Jun 21, 2023 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. Commented Jun 21, 2023 at 10:15

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.