Whether it be adding.
myVar = 5 + 10; // assigned 15
myVar = 12 - 6; // assigned 6
myVar = 13 * 13; // assigned 169
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.
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.
- MYVAR is not the same as myVar or MyVar. For Example:
var someVariable; var thisVariableIsLong; Always remeber camalCase!
Top comments (0)