How to JavaScript Part 1
How to Comment:
In JavaScript you can store a variable with the assignment operator:
Initializing Variable with the Assignment Operator
myVariable = 5;
Assigns the Number value 5 to myVariable.
Assigns the Number value 5 to myVariable.
It is common to initialize a variable to an initial value in the same line as it is declared.
var myVar =0;
or
var a = 9;
meaning a = 9
Understanding Uninitialized Variablesor
var a = 9;
meaning a = 9
When Javascript declares variables, they have an initial value of undefined. Undefined mathamatical operations result in "NaN" or "Not a number" Here is an example of taking undefined variables to defined.
Before:
Initialize these three variables
var a;
var b;
var c;
Do not change code below this line
a = a + 1;
b = b + 5;
c = c + " String!";
After:
Initialize these three variables
var a = 5;
var b = 10;
var c = "I am a"
Do not change code below this line
a = a + 1;
b = b + 5;
c = c + " String!";
camelCaseing
JavaScript is case sensitive and (Oh crap I probably made a million empty pages on the wiki doing this...) and is really important.
Adding/ Subtracting/Multipling and Dividing NumbersNumber is a data type in JavaScript which represents numeric data. Use + to add two numbers together (duh?)
Add:
myVar = 5 + 10; assigned 15
Subtract:
var difference = 45 - 33;
Multiply:
myVar = 13 * 13; assigned 169
Subtract:
myVar = 16 / 2; assigned 8
Increment a Number (add one to a number ) Finding a Remainder in JavaScript