Arithmetic and Relational Operator in typescript
This tutorial explains Arithmetic and Relational Operator in typescript with examples.
Typescript arithmetic operator
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.
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.
|Addition||return values which are computed addition of two or more values|
|Subtraction||return values which are computed subtraction of two or more values|
|Multiplication||return values which are computed multiplication of two or more values|
|Divide||Calculate the division of values|
|Modulus||Return the remainder after the division of values|
|Increment||Increment the value by 1|
|Decrement||Decrement the value by 1|
arithmetic operator 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
Relational operator returns
false to check operands.
Assume values of M are 10 and N is 20.
|Less than equal|
|Greater than equal|
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
Typescript Equality Operators
These operators check the equality of operands.
assume values of C are 10 and D is 20
|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|
|Not equal||It will also do the same logic as the above operator with not equal check|
|Identity Operator||This will checks strict equality without doing type conversion|
|Non Identity||This will check non-strict equality without checking the same types|
To summarize, you learned about typescript operators with examples.
- Arithmetic operator
- Relational operator
- Equality operator