Hello,

could somebody explain such expression

var a = (1.5-1)*2 correct answer is 8

how does this expression calculate?

please.

It evaluates to `1`

. You evaluate first those inside the parentheses. `1.5 - 1`

equals `0.5`

, then you multiply it by `2`

, so you have `1`

.

first this code evaluates the bracket in this case it is 1.5-1.0 = 0.5, then it is multiplied by 2 giving the answer 1 not 8.

yes and I think so tha correct answer is 1 but I have met such quize on faceebook

and all answers was that correct is 8!

do not trust the facebookâs quiz posts:smiley:

Thanks, now I know that such quiz is rubbish

Is it possible, that you have a typo in your example?

`var a = (1,5 - 1) * 2`

will give you `8`

EDIT.

Found a nice explanation: http://www.i-programmer.info/programming/javascript/6524-the-confusing-comma-in-javascript.html

General info on operator precedence: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence

Yes

I have seen again the quiz

and question was var a = (1,5-1)*2;

not var a =(1.5-1)*2;

correct answer 8