<html>
<head>
<title>JavaScript Operators</title>
</head>
<body>
<h1>JavaScript Operators</h1>
<table BORDER="2" CELLPADDING="4" ALIGN="CENTER">
<tr><td>Category</td>
<td>Operator</td>
<td>Description</td>
<td>Usage Example</td>
<td>Value/Result</td></tr>
<tr><td>String</td>
<td>+</td>
<td>concatenation</td>
<td>"Java" + "Script"</td>
<td><script><!--
document.write("Java"+"Script")
// --></script>
</td></tr>
<tr><td ROWSPAN="10">Arithmetic</td>
<td>+</td>
<td>addition</td>
<td>3 + 3</td>
<td><script><!--
document.write(3+3)
// --></script>
</td></tr>
<tr><td ROWSPAN="2">-</td>
<td>subtraction</td>
<td>6 - 2</td>
<td><script><!--
document.write(6-2)
// --></script>
</td></tr>
<tr><td>unary negation</td>
<td>-4</td>
<td><script><!--
document.write(-4)
// --></script>
</td></tr>
<tr><td>*</td>
<td>multiplication</td>
<td>4 * 4</td>
<td><script><!--
document.write(4*4)
// --></script>
</td></tr>
<tr><td>/</td>
<td>division</td>
<td>15/5</td>
<td><script><!--
document.write(15/5)
// --></script>
</td></tr>
<tr><td>%</td>
<td>modulus</td>
<td>22%7</td>
<td><script><!--
document.write(22%7)
// --></script>
</td></tr>
<tr><td ROWSPAN="2">++</td>
<td>increment and then return value</td>
<td>x=4; ++x</td>
<td><script><!--
x=4
document.write(++x)
// --></script>
</td></tr>
<tr><td>return value and then increment</td>
<td>x=4; x++</td>
<td><script><!--
x=4
document.write(x++)
// --></script>
</td></tr>
<tr><td ROWSPAN="2">--</td>
<td>decrement and then return value</td>
<td>x=3; --x</td>
<td><script><!--
x=3
document.write(--x)
// --></script>
</td></tr>
<tr><td>return value and then decrement</td>
<td>x=4; x--</td>
<td><script><!--
x=4
document.write(x--)
// --></script>
</td></tr>
<tr><td ROWSPAN="6">Bit Manipulation</td>
<td>&</td>
<td>and</td>
<td>11 & 7</td>
<td><script><!--
document.write(11&7)
// --></script>
</td></tr>
<tr><td>|</td>
<td>or</td>
<td>8 | 7</td>
<td><script><!--
document.write(8|7)
// --></script>
</td></tr>
<tr><td>^</td>
<td>exclusive or</td>
<td>1 ^ 7</td>
<td><script><!--
document.write(1^7)
// --></script>
</td></tr>
<tr><td><<</td>
<td>left shift</td>
<td>8 << 3</td>
<td><script><!--
document.write(8 << 3)
// --></script>
</td></tr>
<tr><td>>></td>
<td>sign-propagating right shift</td>
<td>-3 >> 2</td>
<td><script><!--
document.write(-3 >> 2)
// --></script>
</td></tr>
<tr><td>>>></td>
<td>zero-fill right shift</td>
<td>-7 >>> 3</td>
<td><script><!--
document.write(-7>>>3)
// --></script>
</td></tr>
<tr><td ROWSPAN="3">Logical</td>
<td>&&</td>
<td>logical and</td>
<td>true && false</td>
<td><script><!--
document.write(true&&false)
// --></script>
</td></tr>
<tr><td>||</td>
<td>logical or</td>
<td>true || false</td>
<td><script><!--
document.write(true||false)
// --></script>
</td></tr>
<tr><td>!</td>
<td>not</td>
<td>!true</td>
<td><script><!--
document.write(!true)
// --></script>
</td></tr>
<tr><td ROWSPAN="6">Comparison</td>
<td>==</td>
<td>equal</td>
<td>3 == 7</td>
<td><script><!--
document.write(3==7)
// --></script>
</td></tr>
<tr><td>!=</td>
<td>not equal</td>
<td>3 != 7</td>
<td><script><!--
document.write(3!=7)
// --></script>
</td></tr>
<tr><td><</td>
<td>less than</td>
<td>3 < 7</td>
<td><script><!--
document.write(3<7)
// --></script>
</td></tr>
<tr><td><=</td>
<td>less than or equal</td>
<td>3 <= 7</td>
<td><script><!--
document.write(3<=7)
// --></script>
</td></tr>
<tr><td>></td>
<td>greater than</td>
<td>3 > 7</td>
<td><script><!--
document.write(3>7)
// --></script>
</td></tr>
<tr><td>>=</td>
<td>greater than or equal</td>
<td>3 >= 7</td>
<td><script><!--
document.write(3>7)
// --></script>
</td></tr>
<tr><td>Conditional Expression</td>
<td>(condition) ? value1 : value2</td>
<td>if condition is true then value1 else value2</td>
<td>true ? 3 : 7</td>
<td><script><!--
document.write(true?3:7)
// --></script>
</td></tr>
</table>
</body>
</html>
|