DEV Community

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

Posted on

1 1

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

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

πŸ‘₯ Ideal for solo developers, teams, and cross-company projects

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay