JavaScript : Variables and Operators
While testing the JavaScript code on your website, there will be times that you will want to write notes to yourself or temporarily remove pieces of code. If you have worked with other programming languages before, you know that most have the capability of commenting out code so that it will not be run when the program is executed.
To comment out a piece of code in JavaScript, you will need to use one of the following two delimiters:
// anything on this line after a double forward slash becomes unprocessed code.
/* the same goes for anything between these marks. This method is preferred for blocking out large portions of code. */
The point of programming is to be able to hold information and manipulate values, so the basic way to do this is with variables. There are no typed variables in JavaScript, a variable is just a value holder. As opposed to being typed as a number or text value, there is just the “var” keyword.
var number = 9;
var name = “jack”;
This also means that you must be careful when manipulating the values. As “name + number” will produce a result. In this case “jack9”. For the most part arithmetic is done by using the symbols we have all come to use in math classes:
+: Addition. It is also used to concatenate strings. Such was the case for “jack9” above.
-: Subtraction
*: Multiplication
/: Division
Not so much in math classes, they are based on integer math:
%: Modulus or modulo will give you the remainder of a division. (i.e. 7 % 3= 1)
++: Increments a number by 1.(i.e. 3++ = 4) You will usually use these with counters.
--: Decrements a number by 1. Also, usually used with counters.
6efbd9b7-de64-49fb-8164-fbbb5cf505bf|0|.0