Javascript Operators

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)  

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;  
Multiplication Operator

The multiplication operator (*) multiplies numbers.

  var x = 5;
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 = yx = y
+=x += yx = x + y
-=x -= yx = x - y
*=x *= yx = x * y
/=x /= yx = 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
&gt;greater than
&lt;less than
&gt;=greater than or equal to
&lt;=less than or equal to
?ternary operator

Javascript Logical Operators

<b>Operator</b><b>Description</b>
&amp;&amp;logical and&nbsp;&nbsp;
||logical or&nbsp;&nbsp;
!logical not

Javascript Type Operators

<b>Operator</b><b>Description</b>
typeofReturns the type of a variable
instanceofReturns true if an object is an instance of an object type