JavaScript Variables Tutorials - Variables and Operators
ASSIGNING VALUES TO VARIABLES:
An operator acts upon a variable and changes its value. Some sample operators are
|
+ Addition/String addition
- Subtraction
* Multiplication
/ Division
% Modulus
|
Most operators are mathematical, i.e. they only work on number variables, Basically ther are 4 different kinds of operators: arithmetic, relational, boolean, and bitwise operators. For now, we will skip the bitwise operators.
Examples of Arithmetic Operators
|
Example Result
a=5; a now equals 5.
a=5; a++ a now increments by 1 and becomes 6.
a=5; a-- a now decrements by 1 and becomes 4.
myName="Fergal"; String myName now contains Fergal.
a=2*3; a now contains the value 6.
a=5-2; a now contains the value 3.
a=5+2; a now equals 7.
|
their are plenty of other operators that you can use, you can lists of these on the internet.
Relational Operators Operator Meaning
|
== equivalent to
!= not equal to
> greater than
< less than
>= greater than or equal to
<= less than or equal to
|
Example Boolean Operators:
|
&& - Returns true if both expressions are true.
|| - Returns true if one expression is true.
! - Used with only one expression.
Returns true if expression is false, false if the expression is true
|