TypeScript Arithmetic Operators

An operator is a symbol that represents a specific action. An arithmetic operator can be used with one or more than values to produce a single value.

In typescript, we can perform arithmetic operations using below given 10 operators.

Arithmetic operators

OperatorNameDescription and Example
x + yAddition Adds two operands.

			let x = 10;
			let y = 20;

			let z = x + y;

			console.log( z );	//Output 30
			
x - ySubtraction Subtracts two operands.

			let x = 10;
			let y = 20;

			let z = x - y;

			console.log( z );	//Output -10
			
-xNegation Negate the sign. Opposite of number.

			let x = 10;

			let z = -x;

			console.log( z );	//Output -10
			
x * yMultiplication Negate the sign. Opposite of number.

			let x = 10;
			let y = 20;

			let z = x * y;

			console.log( z );	//Output 200
			
x ** yExponentiation Multiplies the first operand by itself a number of times which is indicated by the second operand.

			let x = 10;
			let y = 20;

			let z = x ** y;

			console.log( z );	//Output 100000000000000000000 or 1e+20
			
x / yDivision Divides the numerator by the denominator.

			let x = 10;
			let y = 20;

			let z = x / y;

			console.log( z );	//Output 2
			
x % yModulus Returns the remainder after an integer division.

			let x = 10;
			let y = 20;

			let z = x % y;

			console.log( z );	//Output 10
			
x++Increment Increases an integer value by one.

			let x = 10;

			x++;

			console.log( x );	//Output 11
			
x--Decrement Decreases an integer value by one.

			let x = 10;

			x--;

			console.log( x );	//Output 9
			

Above are the arithmetic operators used in typescript.

Drop me your questions in comments section.

Happy Learning !!

Was this post helpful?

Join 7000+ Fellow Programmers

Subscribe to get new post notifications, industry updates, best practices, and much more. Directly into your inbox, for free.

Leave a Comment

HowToDoInJava

A blog about Java and its related technologies, the best practices, algorithms, interview questions, scripting languages, and Python.