Sometimes I want to combine two statements into one to omit curly braces in conditionals. For example, in PHP, instead of writing
if ($direction == 'south-east') {
$x++;
$y++;
}
I would write
if ($direction == 'south-east') $x++ and $y++;
but is there a way to do that in JavaScript? Writing x++ && y++
doesn't seem to work.
Curly braces aren't that bad, but - in very specific cases - you can enhance your code by using commas:
if (direction == 'south-east') x++, y++;
Here's the fiddle: http://jsfiddle.net/FY4Ld/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With