 In this learning activity, we will discuss what a variable is, how to use variables in JavaScript, and how the computer works with variables under the hood. So imagine that you're 13 years old, living at home with your parents. It's a rainy Saturday and you're bored. You decide to call your best friend and ask him to come over and hang out. Would you pick up the phone and say, hey, do you want to come hang out at 227 Elm Street? Probably not. You'd more likely say, hey, do you want to come hang out at my house? Assuming that your friend knows where you live, you'd use the words my house to represent the building at 227 Elm. The phrase my house is what we call an abstraction. We use abstractions all the time in everyday language. You might say, the president is making a speech rather than president Barack Obama is making a speech. We know the president's name, so it's tedious to spell it out every time we refer to him. What's more, before Barack Obama was president, George W. Bush was president. It's also likely that Barack Obama is no longer president. The actual person that the president refers to can change, just as the address of my house will change if your parents ever decide to move to another house. As in everyday language, computer languages use abstractions to represent things that can change, like the address of your home or the name of a president. We call these abstractions variables. Consider this line of JavaScript code. This code pops up a window to ask you to type in your first name. Here's what it looks like in Internet Explorer. That's great, because if the program knows your first name, it can use that piece of information in other places. This is an excellent example of a variable. Oh, wait, there's actually no variable defined in this code, is there? Let's add one. The JavaScript keyword var defines the word first name as a variable. After this line of code executes, first name represents whatever you typed into this prompt box. Let's add another line of code to say hello to you using your first name. Now if you run this and enter Carl, like so, when you select the OK button, you'll see this. So what's really going on here? Under the hood, the computer has two kinds of memory, RAM, or random access memory, and storage. RAM comes on chips or wafers which connect directly to the main system board, which is called the motherboard. Storage takes the form of hard drives, flash drives, SD cards, solid state drives, and the like. Storage is like your closet. That's where stuff gets stored when you're not using it. RAM is like a table or desk. That's where stuff goes when you are using it. Imagine yourself sitting in front of a big empty desk. You get up and go to the closet and pull out a box, which you can think of as a hard drive. You open the box and pull out a file folder. Think of the folder as a directory. You open the folder and pull out a notebook. Think of the notebook as a file. Before we can use the file, we have to move it over to the desk and put it down. In the digital world, we can make copies. So your closet magically makes a copy of this notebook and hands it to you. Now you can put it on the desk and start messing with it. On the first page, you write some stuff. And on the second page, you write some other stuff. But on the third page, you write first name colon Carl at the top of the page. Computers have more room in RAM for files than you have on your desk. So imagine your desk is the size of a football field. Imagine you can magically work with lots of notebooks all over this desk as long as you know where they are. It would make sense to number the positions where notebooks can go. You start with the upper left hand corner, which would be space zero. Computers start counting at zero. They're funny that way. Immediately to the right of location zero would be location one. Location two would be to the right of that. And so on. Okay, now there are millions of notebooks or files on your desk. You've placed the notebook with first name defined on page three at space 132,899. Now imagine that right in front of you on the desk is a master list of the addresses of all of the notebooks and the variables within their notebooks. In this list, you have defined first name as being at space 132,899 on page three. Any time you want to change the value of first name, you look up the address magically zip over to space 132,899, flip to page three, erase the value that was on the paper and change it to something else. It happens so fast that nobody can tell you've even moved. Now here's the thing. When I want to use your first name in a page on another notebook, I only refer to it by the word first name and not by Carl because the value could change. That's why they're called variables because the values that they refer to can vary or change. In our case, first name refers to the value Carl, but any piece of code that knows the address of first name can change the value. Going back to JavaScript, when you create the variable first name, like so, the web browser claims an area of RAM to store the value Carl. It needs to know at least two pieces of data in order to define this variable. The memory address and the number of memory units or bytes that it consumes. This is a simplification for simplicity's sake, but the basic idea is there. Somewhere in the browser's memory, there's a list of all the variables defined. Each entry in the list contains the address of the variable, the length, and the variable's name. The second line of code finds the variable first name in the list, reads the number of bytes at the associated memory address, and returns it to your program, where it can be displayed in an alert box as Carl. In this learning activity, we discovered that a variable is an abstraction that represents some value. Variables can change, but the variable's name does not. Any piece of code that has access to a variable can read its value and change its value. A variable's value is stored in RAM and can be retrieved and used in your program.