.png)
Javascript Operators
Javascript Operators
Assignment Operator
Assign values to variables and add them together:
var x = 5; // assign the value 5 to x
var y = 2; // assign the value 2 to y
var z = x + y; // assign the value 7 to z (5 + 2)
var y = 2; // assign the value 2 to y
var z = x + y; // assign the value 7 to z (5 + 2)
The assignment operator (=
) assigns a value to a variable.
var x = 10;
Addition Operator
The addition operator (+
) adds numbers:
var x = 5;
var y = 2;
var z = x + y;
var y = 2;
var z = x + y;
Multiplication Operator
The multiplication operator (*
) multiplies numbers.
var x = 5;
var y = 2;
var z = x * y;
var y = 2;
var z = x * y;
JavaScript Arithmetic Operators
Arithmetic operators are used to perform arithmetic on numbers:
<b><u class="cdx-underline">Operator</u></b> | <b><u class="cdx-underline">Description</u></b> |
+ | Addition |
- | Subtraction |
* | Multiplication |
** | Exponentiation |
/ | Division |
% | Modulus |
++ | Increment |
-- | Decrement |
Javascript Assignment Operator
Assignment operators assign values to JavaScript variables.
<b>Operator</b> | <b>Example</b> | <b>Same As</b> |
= | x = y | x = y |
+= | x += y | x = x + y |
-= | x -= y | x = x - y |
*= | x *= y | x = x * y |
/= | x /= y | x = x / y<br> |
%=<br> | x %= y<br> | x = x % y<br> |
**=<br> | x **= y<br> | x = x ** y<br> |
Javascript Comparison Operator
<b>Operator</b> | <b>Description</b> |
== | equal to |
=== | equal value and equal type |
!= | not equal |
!== | not equal value or not equal type |
> | greater than |
< | less than |
>= | greater than or equal to |
<= | less than or equal to |
? | ternary operator |
Javascript Logical Operators
<b>Operator</b> | <b>Description</b> |
&& | logical and |
|| | logical or |
! | logical not |
Javascript Type Operators
<b>Operator</b> | <b>Description</b> |
typeof | Returns the type of a variable |
instanceof | Returns true if an object is an instance of an object type |