Every complex statement will introduce precedence problems.
const a = 1 * 2 + 5 / 2 % 2
The result is 2.5, but why? What operations are executed first, and which need to wait?
Some operations have more precedence than the others. The precedence rules are listed in this table:
||unary operators, increment and decrement|
Operations on the same level (like
-) are executed in the order they are found
Following this table, we can solve this calculation:
const a = 1 * 2 + 5 / 2 % 2 const a = 2 + 5 / 2 % 2 const a = 2 + 2.5 % 2 const a = 2 + 0.5 const a = 2.5
Here's my latest YouTube video. I talk about work/life balance as a developer: