Thank you for stopping by! I am a full-stack developer that combines the power of entrepreneurship and programming to make the lives of programmers easier.
Great explanation! I found it quite difficult to explain this feature (albeit in C) in a video or post and you've done a really good job at it!
If you have ever joined programming Facebook groups you will see one question related to this topic pop up quite often:
// What will the value of x be after executing these statements?letx=1;x=x+++++x+x++;
The answer: depends. In JavaScript I get 7, probably because they are evaluated from left to right (and because it is an interpreted environment) but in C or Java you can get some really unexpected results and in most languages it is undefined behaviour.
Thank you for stopping by! I am a full-stack developer that combines the power of entrepreneurship and programming to make the lives of programmers easier.
Operators on the same line have equal precedence. When operators of equal precedence appear in the same expression, a rule must govern which is evaluated first. All binary operators except for the assignment operators are evaluated from left to right; assignment operators are evaluated right to left.
In Java they are also evaluated from left to right (unless you have a x += 1 instead of x++) then it gets confusing.
Great explanation! I found it quite difficult to explain this feature (albeit in C) in a video or post and you've done a really good job at it!
If you have ever joined programming Facebook groups you will see one question related to this topic pop up quite often:
The answer: depends. In JavaScript I get 7, probably because they are evaluated from left to right (and because it is an interpreted environment) but in C or Java you can get some really unexpected results and in most languages it is undefined behaviour.
Undefined behaviour!?
In Java,
x = 1 + 3 + 3 = 7
What is undefined?
In Java they are also evaluated from left to right (unless you have a
x += 1
instead ofx++
) then it gets confusing.Thanks a lot!;)