offline version v3


⊗jsPmBsMOP 19 of 502 menu

Math operations precedence in JavaScript

JavaScript math operations have the same precedence as normal math operations. That is, multiplication and division are done first, addition and subtraction then.

In the following example, 2 is first multiplied by 2, and then 3 is added to the result:

let a = 2 * 2 + 3; alert(a); // shows 7 (the result of 4 + 3)

Determine what will be displayed on the screen without running the code:

let a = 5 + 5 * 3; alert(a);

Determine what will be displayed on the screen without running the code:

let a = 5 + 5 * 3 + 3; alert(a);

Determine what will be displayed on the screen without running the code:

let a = 8 / 2 + 2; alert(a);

Determine what will be displayed on the screen without running the code:

let a = 8 + 2 / 2; alert(a);
enru