If * (multiplication) has higher precedence than /(Division) then why alert is not 1. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

If * (multiplication) has higher precedence than /(Division) then why alert is not 1.

Alert(2×2÷2×2);

4th Jul 2021, 6:20 AM
Dev Sharma
Dev Sharma - avatar
3 Answers
+ 4
in javascript (and most of languages) multiplication has same precedence than division, so left to right associativity occurs ^^ to do multiplication before division, use parenthesis ;P
4th Jul 2021, 6:23 AM
visph
visph - avatar
+ 2
The expression is evaluated from left to right like this 2 * 2 -> (4) (4) / 2 -> (2) (2) * 2 -> (4)
4th Jul 2021, 6:35 AM
Ipang
+ 1
Thanks visph and Ipang
4th Jul 2021, 6:44 AM
Dev Sharma
Dev Sharma - avatar