Create a new variable named book by typing the following and then pressing Return (Mac) or Enter (Windows):
You’ve created your container, or variable, and named it “book.”
Put a value into your new variable by typing the following code.
You’ve now put data inside your variable, where it will be stored.
You only need to type var when you first create and name your variable. When you want to change the data inside your variable, you only need to use the variable’s name.
Now, temporarily forget the name of the book. Got it? Now, imagine that you need to recall the name of the book so that you can tell your friend about it! To recall the data, or value, in a variable, you can just type the name of the variable in the console. So, type the following:
The console recalls the string that was assigned to the book variable and prints it out, as shown here.Printing out the value assigned to a variable.
book = "The Call of the Wild";
The console prints out “The Call of the Wild” (or whatever you entered as the new value of book.
In addition to text, variables can also hold several other different types of data.
The data inside a variable can also be called the value of a variable.