THE BEST NEWSLETTER ANYWHERE

Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

This tutorial explains Arithmetic and Relational Operator in typescript with examples.

`Arithmetic operators`

are used in expressions with two or more entries.

This operator will work on numeric values.

These operators are very easy to understand as these are available in our study curriculums as well as other programming languages.

This evaluates `Arithmetic operators`

on two operands.

Here is a syntax

```
operand1 operator operand2
```

Assume that p has a value of 20, and q has a value of 30.

Operator | Title | Description | Example |
---|---|---|---|

+ | Addition | return values which are computed addition of two or more values | p+q=50 |

- | Subtraction | return values which are computed subtraction of two or more values | q-p=10 |

* | Multiplication | return values which are computed multiplication of two or more values | p*q=600 |

/ | Divide | Calculate the division of values | q/p=1.5 |

% | Modulus | Return the remainder after the division of values | q%p=10 |

++ | Increment | Increment the value by 1 | ++p=21 |

-- | Decrement | Decrement the value by 1 | --q=29 |

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
```

The `Relational`

operator returns `true`

or `false`

to check operands.

Assume values of M are 10 and N is 20.

Operator | Title | Example |
---|---|---|

< | 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(mn) // returns true
console.log(m<=n) // returns false
console.log(m>=n) // returns true
```

These operators check the equality of operands.

assume values of C are 10 and D is 20

Operator | Title | Description | Example |
---|---|---|---|

== | Equality | returns boolean, first check if types are equal, then compare the values of types are objects, then compares references of the same objects if types are not equal, then it will apply strict comparison | M==N returns false |

!= | Not equal | It will also do the same logic as the above operator with not equal check | M!=N returns true |

=== | Identity Operator | This will checks strict equality without doing type conversion | M!=N returns true |

!== | Non Identity | This will check non-strict equality without checking the same types | |

M!=N returns true |

To summarize, you learned about typescript operators with examples.

- Arithmetic operator
- Relational operator
- Equality operator

THE BEST NEWSLETTER ANYWHERE

Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts

Subscribe

You'll get a notification every time a post gets published here.

🧮 Tags

Recent posts

Puppeteer Login Test example How to convert Double to Integer or Integer to double in Dart| Flutter By Example Best ways to fix 504 gateway time out in nodejs Applications Fix for Error No configuration provided for scss Multiple ways to List containers in a Docker with examplesRelated posts