DEV Community

loading...

Notes; JavaScript Algorithms and Data structure.

rthefounding profile image Randy Rivera ・1 min read

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
Enter fullscreen mode Exit fullscreen mode

Subtracting.

myVar = 12 - 6; // assigned 6
Enter fullscreen mode Exit fullscreen mode

Multiplying.

myVar = 13 * 13; // assigned 169
Enter fullscreen mode Exit fullscreen mode

Dividing.

myVar = 16 / 2; assigned 8.
Enter fullscreen mode Exit fullscreen mode

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;
Enter fullscreen mode Exit fullscreen mode
  • 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.
Enter fullscreen mode Exit fullscreen mode
Now let's define them.

      var a = 5;
      var b = 10;
      a = a + 1; // 6
      b = b + 5; // 10.
Enter fullscreen mode Exit fullscreen mode

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!
Enter fullscreen mode Exit fullscreen mode

Discussion (0)

pic
Editor guide