Math consecutive in JavaScript

could somebody explain such expression
var a = (1.5-1)*2 correct answer is 8
how does this expression calculate?

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::smiley:

Thanks, now I know that such quiz is rubbish :slight_smile:

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

var a = (1,5 - 1) * 2 will give you 8

Found a nice explanation:

General info on operator precedence:

Yes :slight_smile:
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