#Commenting out code
// This is a single-line comment. It comments everything out on this line.
var butnotonthisline;
/* This is a multi-line comment. It comments everything out here.
And here.
And all the way here. You need to close the tag to stop the comments */
#Variables
Variables are like garages. They have a address/value, and hold a thing/value. e.g. DDogGarage holds a "red Honda". SJGarage holds a "black Polo". If you know the name of the garage (variable), you can find out what's in it - the variable's value.
First, we create the variable by putting var in front of it, and give it a name.
var ddoggarage;
Then we say what it's value is - i.e. what that name is equivalent to.
ddoggarage = "red Honda";
We can do that in one line if we want to.
var ddoggarage = "red Honda";
Whenever we use ddoggarage
in our code, our code knows that translates to "red Honda".
We use variables so that we don't have to keep repeating things. So say we wanted to do some kind of calculation, and set the value to a variable to use again in the future. We'd do something like this:
var savethisthing = getResultOfSomeCalculation();
s.prop1 = savethisthing;
s.prop2 = "Tickets";
s.prop3 = "Artist name";
s.prop4 = savethisthing;
With the above, the value for the variable savethisthing
is set for prop1 and prop4. We could have written it like the below, but that would be less efficient:
s.prop1 = getResultOfSomeCalculation();
s.prop2 = "Tickets";
s.prop3 = "Artist name";
s.prop4 = getResultOfSomeCalculation();