Array element really the same type?

Hi.
Isn’t this reading assignment a bit dated: https://www.tutorialspoint.com/javascript/javascript_arrays_object.htm
It says “[arrays] stores a fixed-size sequential collection of elements of the same type”. But element can be of different types.
This is a valid array: let array = [3, 'cat', true];

1 Like

I think you missed the sentance after that one. I quote from the website:

“An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.”

You can always store more variable types in an array, but it wants you to think of it as a collection of variables of the same type. I assume they want you to organize arrays as only on type, as it can make some calculations easier. But if you need to you can always do it with more type variables. It really depends on the problem you are trying to solve.

Eloquent Javascript book, in chapter 4 called “Data Structures: Objects and Arrays” has a great example of a problem that needs both objects and arrays. A great read for sure.

1 Like