Moya Richards
4 min readApr 27, 2019
Coding Story Time — What is a variable in computer science?

Coding Story Time — What is a variable in computer science?

A real world story to explain what a variable is in computer science

Coding story time with Moya

So today I went shopping with my friends Anna, Tommy, and John, we have plans to go out tonight, we are going to have so much fun! Anna was broke this week, so I agreed to let her borrow one of my shoes.

So, we got to my house, and Anna and I walked into my closet. Anna looked at the top shelf and screamed out “what are those?”

I looked at her with this weird expression on my face. I think she is talking about my fancy boxes, with shoes in them. So, I said “don’t you see the labels, those are variables”

She said “variables?”, then, I said “those boxes have stuff in them, I labeled them so that I can find them later, that why I call them variables”

Anna had a confused expression crossed her face, so I just said to her,

“a box to you, is like a variable in computer science, they both hold stuff”

A “variable” in Computer Science, is like a box that you label and put stuff into

Anna was still confused

Apparently, Anna still doesn’t understand what a “variable” is, so I asked one of my oldest friend var to come over and explain what a variable is in computer science. var is the oldest command keyword in JavaScript. But, lately var hates being lonely, so var brought along some friends let, and const.

(let me say this in my library whispering voice)
I love “var”, but I am starting to like let and const a lot these days.

But that is a story for another day (maybe later, I’ll tell you about hoisting, that annoying thing that var likes to do).

Oh, man, I started complaining about var, I almost forgot to let you know what var’s speech was about

The JavaScript keyword var explains what variables are in computer science

Before I introduce myself, I really need you to remember this,“variables are in all computer languages”

Well my name is var, and next to me are my friends let and const, we are command keywords and we work in the JavaScript Programming Language.

It’s kind of hard to explain what we do, but I’ll try to anyways. We work with the computer’s memory. Memory in a computer, is like the brain in a human.

Anyways, back to my intro. So, what my friends and I do is this: we help to create a spot in the memory of a computer to hold information, data, thingies, goodies, stuff, value.

I like the word value the most, so I am going to use that word a lot in the rest of my speech.

As commands, our job is to find a spot in memory, and then label it, so that programmers can have a nice name to use for that spot

So, you know how Anna, Tommy, and John are called people, well those named spots in the computer’s memory are called variables

Programmers love big words, and love to shorten concepts, so this whole process of labeling a spot in memory, they like to call that “declaring a variable”.

I am nearing the end of my speech, but, I must tell you this.

We are so cool that you don’t even have to know or try to remember anything about that spot in memory, “just know that you can trust us”.

If you need to put some value, in that spot, just use the name.

Now let’s do a quick recap on variables, I really want to make sure you understand what they are!

So, do you get it? a variable is a named spot in memory, and “my friends and I make those in JavaScript”.

  • a variable is a label for a location in memory
  • variables are used for storing values
  • variables are a storage placeholder for values

Python has no command for declaring a variable

In Python, a variable is created the moment you initialize it (first assign a value to it)

speed = 20; //declaring and initializing variable called speed

JavaScript uses var, let, const

var speed; //declaring variable called speedlet speed; //declaring variable called speedconst speed = 20; //declaring and initializing variable called speed
https://stackblitz.com/edit/js-declaring-variable

Java uses String, int, boolean, etc.

int speed; //declaring integer variable called speed

PHP uses a dollar sign symbol ($)

$speed = 20; //declaring and initializing variable called speed