DEV Community

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

Collapse
 
foresthoffman profile image
Forest Hoffman

I can certainly take a crack at it.

Variables are words/labels that are used to represent information.

Think about what you ate for lunch. For example, let's pretend that you ate a hamburger for lunch. Now, you could tell me that, "I just ate lunch." I would then know that you ate lunch, but I have no idea what you ate. Of course, you would know that you ate a hamburger.

Let's fast forward a day, and you've yet again had lunch. This time you had a salad. You yet again tell me that "I ate lunch!" And yet again, I know that you're referring to some meal you ate in the middle of the day, but I don't know what you ate. Of course, you would know that you ate a salad.

You are able to use the word "lunch" to explain to me that you ate food at some time in the middle of the day. The meaning of "lunch" to me doesn't change. However, the meaning of the word "lunch", to you, changes everyday. That is, unless you eat the same thing several days in a row.

In this analogy, the word "lunch" represents the meal that you consumed on a specific afternoon. It can change at any time. That makes it a variable.

Variables make it easy to refer to information via some kind of label, such as "lunch". You could say to me that you had "lunch" on each day. Or, on the first day, you could tell me that you ate a hamburger around noon, and on the second day, you could tell me that you ate a salad around noon. Using a variable makes things much simpler, since you don't have to be explicit.

Collapse
 
iamjoross profile image
Jose Ross Barredo

Awesome abstraction! I would say that if was a five year old, I would get this!

Collapse
 
foresthoffman profile image
Forest Hoffman

Mission accomplished! :)