# TypeScript Arithmetic and Relational Operators

This tutorial explains TypeScript arithmetic and relational operators with examples.

## #TypeScript Arithmetic Operator

Arithmetic operators are used in expressions involving two or more opernads, working exclusively with numeric values. These operators are fundamental concepts present in study curriculums and various programming languages.

They operate on two operands with the following syntax:

``````operand1 operator operand2
``````

Let’s assume p has a value of 20, and q has a value of 30.

OperatorTitleDescriptionExample
`+`AdditionComputes the sum of two or more values`p+q=50`
`-`Subtractioncalculates subtraction of two or more values`q-p=10`
`*`MultiplicationComputes multiplication of two or more values`p*q=600`
`/`DivideCalculate the division of values`q/p=1.5`
`%`ModulusReturns the remainder after division`q%p=10`
`++`IncrementIncrement the value by 1`++p=21`
`--`DecrementDecrement the value by 1`--q=29`

Example

Here is an arithmetic operator example

``````var m = 50;
var n = 20;
console.log(m + n); // returns 70
console.log(m - n); // returns 30
console.log(m * n); // returns 1000
console.log(m / n); // returns 2.5
console.log(m % n); // returns 10
console.log(++m);    // returns 51
console.log(--n);    // returns 19
``````

## #Relational Operators in TypeScript

The `Relational` operator returns `true` or `false` to check operands.

Assume values of M are 10 and N is 20.

OperatorTitleExample
`<`Less than`M<N` is false
`>`Greater than`M>N` returns false
`<=`Less than equal`M<=N` returns false
`>=`Greater than equal`M>=N` returns false

Following is a Relational Operator Example

``````var m = 50;
var n = 20;
console.log(m < n);  // returns false
console.log(m <= n); // returns false
console.log(m >= n); // returns true
``````

## #TypeScript Equality Operators

These operators check the equality of operands.

Assuming C has a value of 10 and D is 20.

OperatorTitleDescriptionExample
`==`EqualityReturns boolean after comparing values; applies strict comparison if types are not equal`M==N` returns false
`!=`Not equalReturns boolean following similar logic to equality operator but with inequality check`M!=N` returns true
`===`Identity OperatorChecks strict equality without type conversion`M!=N` returns true
`!==`Non IdentityChecks non-strict equality without type consideration`M!=N` returns true

## #Conclusion

In summary, you’ve learned about TypeScript operators with examples.

• Arithmetic operator
• Relational operator
• Equality operator