CodesJava

Easy learning with example program codes

TypeScript Arithmetic Operators Tutorial


TypeScript Arithmetic Operators:

Arithmetic operators are used to perform arithmetic operations.

TypeScript Arithmetic Operators List:

Operator Description Example
+ Addition 30+20 = 50
Subtraction 30-10 = 20
* Multiplication 10*10 = 100
/ Division 50/10 = 5
% Modulus (Remainder) 50%7 = 1
++ Increment var a=10; a++; Result into a = 11
Decrement var a=10; a–; Result into a = 9

TypeScript Arithmetic Operators Example:

var num1:number = 20;
var num2:number = 4;
var result:number = 0;
 
result = num1 + num2;
console.log("Sum: "+result); 
 
result = num1 - num2; 
console.log("Difference: "+result);
 
result = num1*num2;
console.log("Product: "+result);
 
result = num1/num2;
console.log("Quotient: "+result);
 
result = num1%num2;
console.log("Remainder: "+result);
 
num1++ 
console.log("Value of num1 after increment: "+num1);
 
num2-- 
console.log("Value of num2 after decrement: "+num2);

Try it:

JS Bin on jsbin.com
 

Please follow and like us:


Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki