DEV Community

Cover image for Javascript Chapter 4 - Arithmetic Operators in JavaScript
Dzun N
Dzun N

Posted on

Javascript Chapter 4 - Arithmetic Operators in JavaScript

Arithmetic operators in JavaScript are very necessary when we create applications that require logic that requires us to make calculations, whether it is a small number of calculations or a very large number of computations. Therefore I will discuss about "Arithmetic Operators in JavaScript".

Arithmetic / math operators are used to assign values, compare values, perform arithmetic operations, and much more. Arithmetic operators are indispensable when we create applications that require calculation logic. Whether it's a small number or a large number of calculations. And in this tutorial, I will discuss what Arithmetic operators are
Before learning further about javascript arithmetic operators, we will discuss what operators are available in javascript that we can use to create calculation applications using javascript.

Here are the operators that we can use to create arithmetic operators

Operator Description
+ Addition
:-----: :-----:
- Subtraction
* Multiplication
** Exponentiation (ES2016)
/ Division
% Modulus (Remainder)
++ Increment
-- Decrement

HOW TO MAKE ARITHMATIC CALCULATIONS WITH JAVASCRIP

The following is an example of writing to create a javascript arithmetic operator

index.html

In the example above, we made an example of making addition arithmetic operators. By creating two variables and filling in the values of each of these variables, namely variables numbers1 and numbers, where variable1 I fill in the value 5 and variable numbers I fill in the value 8. Then to add them we just need to add the number operator as follows:

document.getElementById('penjumlahan').innerHTML = penjumlahan;
Enter fullscreen mode Exit fullscreen mode

At this point, the summation variable already contains the value of number1 + number2, namely 5 + 8. Then we display the results on the element with the id of addition. And when we try to run it in a web browser, the results are as follows

index.html result

CONCLUSION

Javascript has several arithmetic operators including addition (+), subtraction (-), multiplication (*), division (/), modulus (%), increment (++), decrement (-) which we can use to make an operation mathematics and one of the examples we can apply is by making a calculator with javascript

Top comments (0)