When we talk with each other, we use variables all of the time. In the phrase, “Dasia played Minecraft yesterday; she thinks it is a cool game,” the word “she” is a variable that can mean “Dasia” (in another sentence mean someone completely different) and “it” is a variable that means “Minecraft.” We also talk about things that change as being “variable.” For instance, “the temperature this week has been variable, dropping below zero and rising above 50!”

In mathematics, we learn that a variable is something unknown that can take a value. In early math, you might see a number sentence like: \(2 + □ = 5\); we know that \(□ = 3\). Later on, that becomes \(2 + x = 5\); we know that \(x = 3\) in order for that math sentence to make sense.

In programming, variables can be something unknown that takes a value, as in the case of a variable that takes the value of something that the user inputs. A variable can also take on the value of something more complicated to make referencing that complicated thing more easy. This can be like setting a variable dojo to Kansas City instead of having to type out that word each time you want to use it.

A variable can also be changed; think about having a variable called “high score.”

In Scratch, you can create a data variable and give it a value. The variable can be used by either the sprite or all sprites. You can show your variable and its value on the stage if you want to; this would be useful for a game score.

Additional information about Scratch variables

In JavaScript, you can create a variable and give it a value.

// Note: each of these variable styles mean something different

var myCity = "Kansas City";

// or

let myCity = "Kansas City";

// or

const myCity = "Kansas City";

Additional information about JS variables

Example Projects

Project Ideas

  • Mad Libs

  • Reaction timer that keeps track of the quickest time