简体   繁体   中英

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?

For example some imaginary Math.add which can be used like this:

[ 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

  • For Example 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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