JS Basic Tutorial
JavaScript arithmetic operators are used to perform mathematical operations on numbers. Here’s a list of the main arithmetic operators with examples:
The operands can be literals, variables or the expression.
Operator |
Name |
Description |
---|---|---|
+ |
Addition |
Adds two operands |
- |
Subtraction |
Subtracts the second operand from the first |
* |
Multiplication |
Multiply both operands |
/ |
Division |
Divide the numerator by the denominator |
% |
Modulus |
Outputs the remainder of an integer division |
++ |
Increment |
Increases an integer value by one |
-- |
Decrement |
Decreases an integer value by one |
The addition operator takes two numerical operands and gives their numerical sum. It also concatenates two strings or numbers.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
JavaScript subtraction (-) operator subtracts the right operand from the left operand and produces their difference.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
The JavaScript multiplication operator multiplies two numbers (operands). It gives the product of two operands.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
The JavaScript division (/) operator divides the left operand (dividend) by the right operand (divisor) and returns the quotient.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
The JavaScript modulus (%) operator returns the remainder when first operand is divided by the second operand. It is also known as remainder operator.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
The exponentiation operator raises the first operand to the power of the second operand.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
The JavaScript increment (++) operator increases the value of operand by one. It is an unary operator. It takes only one operand.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
The JavaScript decrement (--) operator decreases the value of operand by one. It is also an unary operator, i.e., it takes only one operand.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>