top of page

Coding 101: CS Variables Simplified

This article will try to simplify the concept of variables in computer science programming. Imagine you are cleaning out your garage. You buy bags to help you organize everything. You can think of these as variables.

You put things of similar types into the same bag. You then label the bag so you know what type of items are in it.

Variables are simply locations of storage that hold information that you can use later.

Data Types

Just how you would label the different bags with names, you would label the variables with names called a data type.

Photo by FORTYTWO on Unsplash

Just like the bag label defines the things going into the bag, the data type defines the type of information that a variable could hold. Depending on the programming language that you use, you will see many different types of predefined data types such as “string”, “integer”, “character”, “Boolean”, “double”, and “float” for Java.

Declaring a variable

Before you can use a variable, you must declare it. See the below format.

{Data Type} {Variable Name} ={Some Value}

ex. string someWords = “random words put together”;

If you want to store a word or combination of characters, you would use the “string” data type. If you wanted to store a number you have a few options such as using an “integer” or “double”.

Next you want to focus on the variable name. You want to use something descriptive so you know what it is in the future when you want to use it.

Going back to our previous analogy, you find a bunch of old pillows when cleaning out your garage. You put all of the pillows into a bag and then name the bag “oldPillows”. This is the variable name for the bag so later when you want a pillow you know which bag to go to.

Finally the value portion. The value is the actual object that we put inside of the bag. So for this our value will be a “pillows”

{Data Type} {Variable Name} ={Some Value}

translates to:

Bag oldPillows = pillows

However, in actual programming we must use coding languages build in data types and rules

Ex. string oldPillows = “pillows”

9 views0 comments

Recent Posts

See All


bottom of page