Sunday, July 22, 2018

Arithmetic and Relational Operator in typescript

The arithmetic operator is 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 Assume that p value is 20 and q value is 30
Operator Title Description Example
+ Addition return values which is 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

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 

this operator returns true or false to check operands assume values of M is 10 and N is 20
Operator Title Example
< Less than M
> Greater than M>N returns false
<= Less than equal M<=N returns false
>= Greater than equal M>=N returns false

Example 


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

Equality Operators 

These operators check equality of operands assume values of C is 10 and D is 20
Operator Title Description Example
== Equality returns boolean, first check if types are equal, then compare the values if 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 like 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 checks non strict equality without check same types M!=N returns true

Related article