If I want to increment a value and then store it in another variable, why is it not possible to do it on one line of code?
This works
var count = 0;
count++;
var printer = count;
alert(printer); //Prints 1
But this doesn’t
var count = 0;
var printer = count++;
alert(printer); //Prints 0
You’re using the post-incrementing operator. The increment happens after the assignment expression is complete.
Use the pre-incrementing version instead…
Or use the
+=operator…