Let's assume that you want to decrease a value until it reaches zero and stop there.
Example:
javascriptif(value > 0) value --; else value = 0;
An alternative to the previous code:
javascriptvalue = value - 1 < 0 ? 0 : value - 1;
Another one:
javascriptvalue = Math.max(0, value - 1);
Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.