Last Updated: February 25, 2016
·
2.117K
· alexanderbrevig

Post increment gotcha

Try to answer this without testing:

c=2;
c = 1 + c++;
// c = 3 or 4 ?

Compare it to:

c=2;
c = 1 + (++c);
// c = 3 or 4 ?

Finally:

c=[1,2,3];
i = 1;
c[i] = i++:
// c[1] = 1 or 2, or c[2] = 2 ?

1 Response
Add your response

i enjoyed this brain exercise! a very original tip -- kudos.

over 1 year ago ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside