Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Show the difference between a++ and ++a
* update quantity based on button type
* make sure we don't go below zero
if( action_type === 'minus' ) {
// this returned my value, then decremented it, so it never saved
// hitting the minus button always resulted in the same number
quantity = quantity ? quantity-- : 0;
// this decremented my value, then returned it
// which works as expected
quantity = quantity ? --quantity : 0;
} else if ( action_type === 'plus' ) {
// either of these are fine, because I'm not returning the value,
// just using it later down the live
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment