Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
So anytime we're working with variables, we really have two things. We have the variable, the container, the bucket, and we have the different values that we're going to put in it from moment to moment. Now, the most common kind of values in computer programs are numeric values, numbers, and really this is no surprise. Sure, these days, when we use the word computer, we think of a machine. But for hundreds of years, computer was a job. In the 17th, 18th, 19th centuries, you could be employed as a computer.
It just meant a person who computes, someone who does calculations. Then these machines come along and they do it far better than the person ever could. These days we think a computer means hardware. But the reason they were invented was always about number crunching. But we need to be comfortable with our use of numbers. When we're writing programs, we're dealing with bank balances and dollars and cents, the position of a spaceship on the screen, the height and width of a web browser window, the coordinates of a device using geolocation, the amount of milliseconds we've been playing an MP3 song, even colors are represented with numeric ranges of red, green, and blue. All numbers.
So on the next statement, I will set that variable to the number 5. Now, when you're brand-new to programming, lines like a = 5 and b = 10 can look a little weird, particularly if the last time you saw anything like this was equations in school. But remember, when you see the equals sign here, this is not a polite description. This is a command. This is an instruction. This is saying take the value 5 and put it in the variable called a.
I don't care what a was before, but after this line of code is executed, it will have the value 5. This is what the equals sign does. It assigns a value. That's why it's formally called the assignment operator. Now, notice that there are no quotes around the number 5. The number 5 here is referred to as a numeric literal. It represents the fixed value 5. The variable part of this line can change as our program runs, but the literal does not.
Now, as one final note, understand there's a very big difference between creating a variable like this, var b = 123, and creating a variable like this, var c =. Similar looking value, but inside quotes. Well, the first one here, var b, is a number 123. The second one, var c, is a string. Not the number 123, but the digits 1, 2, 3 and sometimes that's a pretty big difference in behavior.
So let's talk about strings next.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 105383 Viewers
56 Video lessons · 117101 Viewers
71 Video lessons · 86317 Viewers
131 Video lessons · 41253 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.