Operators

Arithmetic a = 12, b = 4
+
--
*
/
%
++
– –
Addition
Subtraction
Multiplication
Division
Modulus
Increment
Decrement
a
a
a
a
a
a
a
+
--
*
/
%
++
– –
b
b
b
b
b
16
8
48
3
0
13
11

 

Assignment a = 12, b = 4
=
+=
-=
*=
/=
%=
Assign to
Add and assign
Subtract and assign
Multiply and assign
Divide and assign
Modulus and assign
a
a
a
a
a
a
=
+=
-=
*=
/=
%=
b
b
b
b
b
b
b now equals 12
a now equals 4
a now equals 8
a now equals 48
a now equals 3
a now equals 0

 

Comparison a = 12, b = 4
==
!=
>
<
>=
<=
Equality
Inequality
Greater than
Less than
Greater than or equal
Less than or equal
a
a
a
a
a
a
==
!=
>
<
>=
<=
b
b
b
b
b
b
false
true
true
false
true
false

 

Logical a = 12, b = 4
&&
||
!
And
OR
NOT
a
a
a
&&
||
!
b
b
b
true
true
!(a||b) = false
reverses condition

 

Conditional a = 12, b = 4
a > ? : Ternary a > b ? car : bike car 

 

 

typeof
Unary operator placed before a single operand (which can be of any type) and returns true or false based on an evaluation or a string indicating the data type of the operand.

 

Number “number”
String “string”
Boolean “boolean”
Object “object”
Function “function”
Undefined “undefined”
Null “object”

Save & refresh browser:

a is a number
b is a string

Leave a Reply