简体   繁体   English

Javascript中是否有内置的算术函数?

[英]Are there built-in arithmetic functions in Javascript?

Very simple (stupid?) question: are there built-in arithmetic functions in JS such as addition or multiplication? 非常简单(愚蠢的?)问题:JS中是否存在诸如加法或乘法之类的内置算术函数?

For example some imaginary Math.add which can be used like this: 例如,一些虚构的Math.add可以这样使用:

[ 3, 1, 2 ].reduce( Math.add ) // 6

No but you could very easily define this yourself: 不,但是您可以很容易地自己定义:

const add = (x, y) => x + y;
[ 3, 1, 2 ].reduce( add );

hi lucifer63 the function you are asking for like add, sum might not be available but that you can do by the operator but for the little complex operation we do have lucifer63您好,您要求的功能,例如加法,求和可能不可用,但您可以由操作员来做,但对于一点点复杂的操作,我们确实有

  • For Example Math.round(4.7); 例如Math.round(4.7); Math.PI; Math.pow(8, 2); Math.sqrt(64);

if you check out the w3school Link you can find more math function's which are also very usefull 如果您查看w3school Link,您会发现更多的数学函数也非常有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM