Arithmetic Operators

Introduction

Arithmetic operators are used in JavaScript to perform basic mathematical calculations. They are essential for handling numbers, building formulas, and creating dynamic logic in web applications.

Understanding arithmetic operators is one of the first steps in learning programming because they are used in almost every type of application.

Core Arithmetic Operators

Addition
The addition operator is used to add two values together.
Example
let result = 5 + 3

Subtraction
The subtraction operator is used to subtract one value from another.
Example
let result = 10 – 4

Multiplication
The multiplication operator is used to multiply two values.
Example
let result = 6 * 2

Division
The division operator is used to divide one value by another.
Example
let result = 12 / 3

Modulus
The modulus operator returns the remainder after division.
Example
let result = 10 % 3

Increment
The increment operator increases a value by one.
Example
let x = 5
x++

Decrement
The decrement operator decreases a value by one.
Example
let x = 5
x–

Practical Usage

Arithmetic operators are commonly used in calculations such as totals, averages, counters, and dynamic data updates. For example, they can be used in shopping carts to calculate total prices or in forms to compute user input values.

Best Practices

Use clear variable names when performing calculations
Always check for division by zero to avoid errors
Combine operators carefully to maintain readability

Conclusion

Arithmetic operators form the foundation of mathematical operations in JavaScript. Mastering them allows you to build efficient and logical programs for real world applications.

Home ยป JavaScript Fundamentals (Beginner Level) > Operators and Conditions > Arithmetic Operators