# Math Operations

**URL:** <https://forum.kirupa.com/t/math-operations/643770>\
**Category:** Uncategorized\
**Created:** [August 4, 2020, 4:09pm UTC](https://forum.kirupa.com/t/math-operations/643770 "2020-08-04T16:09:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Stern](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/john_stern/32/12050_2.png) [@John\_Stern](https://forum.kirupa.com/u/John_Stern)\
**Post date:** [August 4, 2020, 4:09pm UTC](https://forum.kirupa.com/t/math-operations/643770/1 "2020-08-04T16:09:59Z")

</div>

var deMo = function (a,b,c) {  
var maTh = a -b \* c;  
return maTh;  
};  
println(deMo(19,10,2));

```
    //19 - 10 * 2 = 18
    
    I thought that subtraction takes precedence over multiplication - no ? The println returned a value of -1 indicating the opposite. What gives?
```

---

<div class="post-metadata">

**Author:** ![John\_Stern](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/john_stern/32/12050_2.png) [@John\_Stern](https://forum.kirupa.com/u/John_Stern)\
**Post date:** [August 4, 2020, 4:14pm UTC](https://forum.kirupa.com/t/math-operations/643770/2 "2020-08-04T16:14:28Z")

</div>

var deMo = function (a,b,c) {  
var maTh = a -b \* c;  
return maTh;  
};  
println(deMo(19,10,2));

```
    //19 - 10 * 2 = 18
    
    I thought that subtraction takes precedence over multiplication - no ? The println returned a value of -1 indicating otherwise.

```

(I don’t think my first posting captured the entirety of my issue)

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [August 4, 2020, 4:24pm UTC](https://forum.kirupa.com/t/math-operations/643770/3 "2020-08-04T16:24:03Z")

</div>

Multiplication (and division) has precedence over subtraction (and addition). For more on precedence, see: [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator\_Precedence](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence)

---

<div class="post-metadata">

**Author:** ![John\_Stern](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/john_stern/32/12050_2.png) [@John\_Stern](https://forum.kirupa.com/u/John_Stern)\
**Post date:** [August 5, 2020, 2:12am UTC](https://forum.kirupa.com/t/math-operations/643770/4 "2020-08-05T02:12:07Z")

</div>

> [@senocular](#):
>
> Multiplication (and division) has precedence over subtraction (and addition). For more on precedence,

hah - who knew ? - thanks for setting me straight on this

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [August 5, 2020, 2:24am UTC](https://forum.kirupa.com/t/math-operations/643770/5 "2020-08-05T02:24:53Z")

</div>

In school we memorized the order of operations as **PEMDAS** : Parenthesis, exponents, multiplication, division, addition, subtraction 😛

(Addition and subtraction are actually the same. Whichever one is first will win!)
