JavaScript+Operators
JavaScript Operators
Overview
Operators in JavaScript are special symbols that perform operations on variables and values.
Arithmetic Operators
These operators are used to perform basic mathematical operations.
Operator Descriptions and Examples:
+ (Addition):
Example:
X=2, Y=3; X+YResult:
5
- (Subtraction):
Example:
X=6, Y=3; X-YResult:
3
* (Multiplication):
Example:
X=2, Y=3; X*YResult:
6
/ (Division):
Example:
X=9, Y=3; X/YResult:
3,Example:
X=5, Y=2; X/YResult:
2.5
% (Modulus):
Example:
5%2,10%8,10%2Results:
1,2,0
++ (Increment):
Example:
X=5; X++Result:
X=6
-- (Decrement):
Example:
X=5; X--Result:
X=4
Assignment Operators
These operators are used to assign values to variables.
Operator Examples (is the same as):
=
Example:
x=y
+=
Example:
x+=yEquivalent to
x= x + y
-=
Example:
x-=yEquivalent to
x= x - y
*=
Example:
x*=yEquivalent to
x= x * y
/=
Example:
x/=yEquivalent to
x= x / y
%=
Example:
x%=yEquivalent to
x= x % y
Comparison Operators
These operators are used to compare two values.
Operator Descriptions and Examples:
== (is equal to):
Example:
x==9Result:
false
=== (is exactly equal to):
Example:
x==5is trueExample:
x=="5"is false
!= (is not equal):
Example:
x!=9is true
> (is greater than):
Example:
x>9is false
< (is less than):
Example:
x<9is true
>= (is greater than or equal to):
Example:
x>=9is false
<= (is less than or equal to):
Example:
x<=9is true
Note: Assume
x=5
Logical Operators
Logical operators are used to determine the logic between variables or values. They can operate on non-Boolean values as well.
Operator Descriptions and Examples:
**&& (AND