What are Arithmetic Operators in typescript? How to use Aritmatic operators in TypeScript?

Опубликовано: 11 Март 2026
на канале: TypeScript Insights
198
3

In TypeScript, arithmetic operators are symbols used to perform basic mathematical calculations on numeric data types. These operators work similarly to those in JavaScript. Here are the arithmetic operators available in TypeScript:

1. Addition (+): Adds two operands together.
2. Subtraction (-): Subtracts the second operand from the first operand.
3. Multiplication (*): Multiplies two operands.
4. Division (/): Divides the first operand by the second operand.
5. Modulus (%): Returns the remainder after division of the first operand by the second operand.
6. Increment (++) and Decrement (--): These operators increase or decrease the value of a variable by one.

Here's a brief example of using arithmetic operators in TypeScript:

```typescript
let a: number = 10;
let b: number = 5;

let additionResult: number = a + b; // 10 + 5 = 15
let subtractionResult: number = a - b; // 10 - 5 = 5
let multiplicationResult: number = a * b; // 10 * 5 = 50
let divisionResult: number = a / b; // 10 / 5 = 2
let modulusResult: number = a % b; // 10 % 5 = 0

let c: number = 7;
c++; // Increment c by 1, now c is 8
c--; // Decrement c by 1, now c is 7 again
```

Keep in mind that arithmetic operators only work with numeric data types. If you attempt to use them with other data types, you may encounter unexpected behavior or errors.