Next freebie in 28 Hours*
Since we’re talking about variables, here’s some sound advice. As you’ll be using a lot of them in your programming, we suggest you always create variables which have a useful name. If you want to create a variable to hold the first name of a person, don’t name it it something random like ‘var cow;’. Use names that describe the variable's content such as ‘var firstName’. The more descriptive your variable names are, the more readable your code will be.
var firstString = “Hello Earth”;
var firstString = “Hello Earth” + “, I am back”;
What happened here? The + sign joined the two strings together and stored it in the variable firstString: now firstString has “Hello Planet, I am back” stored in it.
The same can be done with variables. For example if we have var testString = “Hello People” what happens when we call alert like this:
alert(testString + testString);
You got it right if you guessed we get a pop up box showing “Hello People Hello People.” String variables can also be joined using the magical + sign.
What’s the point of this lecture and all these tips? As you gain experience as a programmer you will realize how important it is to have clean code with meaningful variables. It not only helps you but it helps anyone who reads it to manage and understand your code.
Have a question but don't want to ask it publicly? If you are a prime member just ask right here and we will get back to you within 48 hours. Not prime yet? no worries you can ask publicly below.