Skip to content

Instantly share code, notes, and snippets.

@Willshaw
Last active January 28, 2019 05:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Willshaw/92cc0f57c262aeada467860d5b0b81f0 to your computer and use it in GitHub Desktop.
Save Willshaw/92cc0f57c262aeada467860d5b0b81f0 to your computer and use it in GitHub Desktop.
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
item_quantity++;
++item_quantity;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment