Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
It understands these are numbers. It adds them together. If on the other hand, I create these variables with the digit 5, but inside double quotes as a string and then I use exactly the same code, I'm using the addition operator to add them together, what's going to happen is concatenation, not addition. They are going to put them beside each other and what will be output is 55. This is a behavior you do occasionally want to have happen even when the values in your strings are what we think of as numeric.
So you're working with area codes and phone numbers. You don't want to be in a situation where those will get added to each other and actually have a different number, you want them concatenated one beside the other. Now it might get a little more puzzling, but what happens if you've got one of each? So what happens if one variable is a number and the other variable is a string? Well, what's going to happen is if one is a string, that's going to take charge. You'll get concatenation will occur. Now where it can get even a bit more involved is what happens if you try and do something that just doesn't make sense.
Because sometimes we have variables that we want to be a number, but aren't. Let's say for example we've got a variable equal to the string 55, so it could be numeric, but it could be abc. It could be an exclamation mark. Perhaps we're asking somebody to type in a value into a prompt box. We hope it's a number, but it might not be. Well, what I can do first is I can create a new variable. I'll call it myNumber. I'm going to try and convert whatever is in foo into a number.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 98566 Viewers
61 Video lessons · 85854 Viewers
71 Video lessons · 69749 Viewers
56 Video lessons · 102056 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.
Your file was successfully uploaded.