JavaScript Arithmetic Operators

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.

var z = 3 + 5; // 3 and 5 are literal values.
const x = 3; y = 5;
var z = x + y ; // x and y are variables.
var z = 3 + 2*x // 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

1. Addition (+):


The addition operator takes two numerical operands and gives their numerical sum. It also concatenates two strings or numbers.

Example

<!DOCTYPE html>

<html>

<head>

<title>Page Title</title>

</head>

<body>


<h1>This is a Heading</h1>

<p>This is a paragraph.</p>


</body>

</html>

2. Subtraction (-):


JavaScript subtraction (-) operator subtracts the right operand from the left operand and produces their difference.

Example

<!DOCTYPE html>

<html>

<head>

<title>Page Title</title>

</head>

<body>


<h1>This is a Heading</h1>

<p>This is a paragraph.</p>


</body>

</html>

3. Multiplication (*):


The JavaScript multiplication operator multiplies two numbers (operands). It gives the product of two operands.

Example

<!DOCTYPE html>

<html>

<head>

<title>Page Title</title>

</head>

<body>


<h1>This is a Heading</h1>

<p>This is a paragraph.</p>


</body>

</html>

4. Division (/):


The JavaScript division (/) operator divides the left operand (dividend) by the right operand (divisor) and returns the quotient.

Example

<!DOCTYPE html>

<html>

<head>

<title>Page Title</title>

</head>

<body>


<h1>This is a Heading</h1>

<p>This is a paragraph.</p>


</body>

</html>

5. Modulus (%):


The JavaScript modulus (%) operator returns the remainder when first operand is divided by the second operand. It is also known as remainder operator.




Example

<!DOCTYPE html>

<html>

<head>

<title>Page Title</title>

</head>

<body>


<h1>This is a Heading</h1>

<p>This is a paragraph.</p>


</body>

</html>

6. Exponentiation (**):


The exponentiation operator raises the first operand to the power of the second operand.

Example

<!DOCTYPE html>

<html>

<head>

<title>Page Title</title>

</head>

<body>


<h1>This is a Heading</h1>

<p>This is a paragraph.</p>


</body>

</html>

7. Increment (++):


The JavaScript increment (++) operator increases the value of operand by one. It is an unary operator. It takes only one operand.

Example

<!DOCTYPE html>

<html>

<head>

<title>Page Title</title>

</head>

<body>


<h1>This is a Heading</h1>

<p>This is a paragraph.</p>


</body>

</html>

8. Decrement (--):


The JavaScript decrement (--) operator decreases the value of operand by one. It is also an unary operator, i.e., it takes only one operand.

Example

<!DOCTYPE html>

<html>

<head>

<title>Page Title</title>

</head>

<body>


<h1>This is a Heading</h1>

<p>This is a paragraph.</p>


</body>

</html>

Whereisstuff is simple learing platform for beginer to advance level to improve there skills in technologies.we will provide all material free of cost.you can write a code in runkit workspace and we provide some extrac features also, you agree to have read and accepted our terms of use, cookie and privacy policy.
© Copyright 2024 www.whereisstuff.com. All rights reserved. Developed by whereisstuff Tech.