DEV Community

Discussion on: Explain variables in programming like I'm five

Collapse
 
mohanarpit profile image
Arpit Mohan

This is a great question. Although Forest Hoffman nailed it, I'll still give it a shot.

Think of a variable as a pizza box. Now, the box may contain a pepperoni pizza, chicken pizza or no pizza at all. Just by looking at the box, you don't know what's in it. The only way to find out is to actually open the box.
Now, if I ask you to bring me the pizza from the refrigerator, you'll pick up the pizza box and hand it over to me. The box allows you to conveniently move the pizza from one location to another. It gives both of us a handy way to refer to the pizza and also move it around. So, the box is the variable and the pepperoni is the value of the variable.

Collapse
 
foresthoffman profile image
Forest Hoffman

That's a good way to explain it too. I think you could even extend this to talk about data types.

Collapse
 
mohanarpit profile image
Arpit Mohan

Thanks. That was the original intention. Wanted to also add the different types of boxes such as pizza box, cake box etc to show different data types. But then, I thought it would complicate the answer, so chickened out at the end. :D

Thread Thread
 
michael profile image
Michael Lee 🍕

Please do elaborate with the different boxes. Think it's helpful in visualizing how variables work. Plus you did an awesome job in illustrating with pizza. Pizza speaks dearly to my heart.