DEV Community

Discussion on: Why should one use multiple Variables when you could store everything in an array?

Collapse
 
terabytetiger profile image
Tyler V. (he/him)

Your mom tells you you have to clean your room. You have 2 options:

a) Throw everything into your closet, close the door and when you need something you can find it by digging through and looking for it (using a single array for everything)

b) Take the time to sort everything into their proper location, making it easier to find if you need a specific thing (multiple variables).

The quick and dirty way is to throw things into an array, but as you .push things to the array, you have to keep track of what is pushed when, otherwise you won't know how to reference the values later. If you sort things into the appropriate variables, they'll be much easier to reference later on!

Collapse
 
morrisjohn profile image
Morris John

Thanks. I loved the room cleaning analogy