TypeScript 算术运算符

TypeScript 算术运算符

原文: https://howtodoinjava.com/typescript/arithmetic-operators/

运算符是代表特定动作的符号。 算术运算符可以与一个或多个值一起使用以产生单个值。

在 TypeScript 中,我们可以使用下面给出的 10 个运算符执行算术运算。

算术运算符

x + y,加法,相加两个操作数。

			let x = 10;
			let y = 20;

			let z = x + y;

			console.log( z );	//Output 30

x - y,减法,相减两个操作数。

			let x = 10;
			let y = 20;

			let z = x - y;

			console.log( z );	//Output -10

-x,取反,翻转标志,求相反数。

			let x = 10;

			let z = -x;

			console.log( z );	//Output -10

x * y,乘法,相乘两个运算符。

			let x = 10;
			let y = 20;

			let z = x * y;

			console.log( z );	//Output 200

x ** y,求幂,将第一个操作数乘以自己,重复第二个操作数指示的次数。

			let x = 10;
			let y = 20;

			let z = x ** y;

			console.log( z );	//Output 100000000000000000000 or 1e+20

x / y,除法,分子除以分母。

			let x = 10;
			let y = 20;

			let z = x / y;

			console.log( z );	//Output 2

x % y,模量,返回整数除法后的余数。

			let x = 10;
			let y = 20;

			let z = x % y;

			console.log( z );	//Output 10

x++,递增,将整数值增加一。

			let x = 10;

			x++;

			console.log( x );	//Output 11

x--,递减,将整数值减一。

			let x = 10;

			x--;

			console.log( x );	//Output 9

以上是 TypeScript 中使用的算术运算符

将我的问题放在评论部分。

学习愉快!