After reading these two posts:
- ++someVariable Vs. someVariable++ in Javascript
- http://community.sitepoint.com/t/variable-vs-variable/6371
I am still confused on the following code:
var num = 0;
num++ // returns 0
++num // returns 1
Why dose num++
return 0?
I understand that it assigns first, then adds one, but I still don't understand why it doesn't display the 1.
var num = 0;
num++ // returns 0
num // returns 1
I am really confused with the following example:
Example:
var num = 0;
num++
// assigns then increments
// So if it assigns the num = 0, then increments to 1, Where is one being
//stored? Is it assigned anywhere?
Or does it assign the expression.
(I imagine the expression is this: num = num + 1;)
This is probably my best guess but it still isn't 100% clear to me, I still don't understand why num++ displays/returns 0 instead of having the expression being evaluated and returning 1.