Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How come Javascript arrays can hold multiple data-types at same time? [closed]

I've just picked up javaScript and i am amazed to see that javaScript arrays can hold any type of data in them, for example, a number and a string both can be stored in a single array. well, i've always studied in my Data Structures classes that "Array is a container which can hold fix number of items and these items should be of same type". My question is :- Is javascript a special case? or, they have changed the definition of array?

like image 655
Rahul Kumar Avatar asked Sep 08 '26 14:09

Rahul Kumar


1 Answers

Quoting Mozilla JS Reference on this:

Arrays are list-like objects whose prototype has methods to perform traversal and mutation operations. Neither the length of a JavaScript array nor the types of its elements are fixed.

More on this can be found here

like image 180
Ehimah Obuse Avatar answered Sep 11 '26 05:09

Ehimah Obuse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!