It was time to start working on adding or subtracting(dividing, multiplying and so forth) numbers in JavaScript.
Whether it be adding.
myVar = 5 + 10; // assigned 15
Subtracting.
myVar = 12 - 6; // assigned 6
Multiplying.
myVar = 13 * 13; // assigned 169
Dividing.
myVar = 16 / 2; assigned 8.
After completing some challenges I went ahead and started working understanding Uninitialized variables, Initializing variables with the assignment operator, Case sensitivity in Variables.
NOTES:
You can initialize a variable to a initial value in the same line as it is declared as followed:
* var myVar = 0;
- variable called myVar and assigns it to a initial value of 0.
When the variables are declared and also have a initial value of undefined, if you do a mathematical operation on an undefined variable you will be Getting NaN ( "Not a Number" ). Example:
var a;
var b;
a = a + 1;
b = b + 5;
This will you give undefined.
Now let's define them.
var a = 5;
var b = 10;
a = a + 1; // 6
b = b + 5; // 10.
In JavaScript is extremely important that all variables and function names are case sensitive. (Capitalization matters)
- MYVAR is not the same as myVar or MyVar. For Example:
var someVariable;
var thisVariableIsLong;
Always remeber camalCase!
Top comments (0)