Skip to main content

Operators

The most common type of JavaScript expression is the numeric expression that combines numeric operands and arithmetic operators to produce a numeric result. JavaScript's basic arithmetic operators are more or less the same as those found on the numeric keypad of most modern computer keyboards, plus a couple of extra operators for more advanced work.

Operator Name Example Result
+ Addition 10 + 4 14
++ Increment 10++ 11
- Subtraction 10 - 4 6
- Negation -10 -10
-- Decrement 10-- 9
* Multiplication 10 * 4 40
/ Division 10 / 4 2.5
% Modulus 10 % 4 2


Example: Using the + Operator

 
<script language="JavaScript" type="text/javascript">
<!--
var number1 = eval(prompt("Enter the first number:", 0))
var number2 = eval(prompt("Enter the second number:", 0))
var sum_result = number1 + number2
alert(sum_result)
//-->
</script>
 

Next: Using Comparison Operators