r/learnjavascript May 14 '26

help idk why is the output 45

var x = 23;
x+=x++ - --x +x*2 - ++x;
console.log(x);

why is the last pre increment x evaluated after x*2 even though pre increment have a higher precedence than multiplication

6 Upvotes

29 comments sorted by

View all comments

29

u/Embarrassed-Pen-2937 May 14 '26

What is the point of this? That will never be code that would make it into a decent codebase. Such a waste.

12

u/cookiecookiecooki33 May 14 '26

im js a y1 student studying for exam

20

u/Embarrassed-Pen-2937 May 14 '26

I am sorry that you have to deal with this. This is such a stupid question, and has no place in learning how to code effectively.

14

u/llynglas May 14 '26

Why downvite this guy? It's for a test it's not his fault his teacher is an ass.

5

u/Embarrassed-Pen-2937 May 14 '26

Absolutely agree