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
Operator | Name | Description and Example |
---|---|---|
x + y |
Addition |
Adds two operands.
let x = 10; let y = 20; let z = x + y; console.log( z ); //Output 30 |
x - y |
Subtraction |
Subtracts two operands.
let x = 10; let y = 20; let z = x - y; console.log( z ); //Output -10 |
-x |
Negation |
Negate the sign. Opposite of number.
let x = 10; let z = -x; console.log( z ); //Output -10 |
x * y |
Multiplication |
Negate the sign. Opposite of number.
let x = 10; let y = 20; let z = x * y; console.log( z ); //Output 200 |
x ** y |
Exponentiation |
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 / y |
Division |
Divides the numerator by the denominator.
let x = 10; let y = 20; let z = x / y; console.log( z ); //Output 2 |
x % y |
Modulus |
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 !!