Last active
January 28, 2019 05:31
-
-
Save Willshaw/92cc0f57c262aeada467860d5b0b81f0 to your computer and use it in GitHub Desktop.
Show the difference between a++ and ++a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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