Questions about data types

So, I’m learning JS now, but I also have a little experience in Python.

In Python, there is data type dictionary which is cool, when you need to store data in key:value format, and also it is mutable.

As far as I understand if we need something like this in JS, we are creating objects? There was such challenge in the curriculum. Correct me if I’m wrong.

And there also is such data type as tuple. It’s like Python’s lists, or arrays in JS, but it’s immutable. I kinda liked to use it because of immutability: it’s easier not to mess up something immutable.

So i’ve just tried to search ‘how to make something like tuple in JS’. I’m reading this article but for some reason having hard time with that. Any advice about this matter?

There’s no immutable tuple type in JavaScript.

If you want an immutable array, you can pass an array to Object.freeze(). I feel like I don’t see it used much though. It seems to be more common to use the array methods that return a new array like map(), filter(), reduce(), etc. to “maintain immutability” manually.

FYI @admit8490 tuples are most likely coming to JS down the road. It may be a while, as the proposal is only at stage 2. But I wouldn’t bet against it.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.