Learn Create Your Own Split Screen

Next Page

Let's learn another shortcut.

You already know about statements like this:

score = score + 1; alien_count = alien_count - num_killed; width = width * 2;
And we've also met this short-cut:
score++; // same as score = score + 1
You can also express it like this:
score+= 1; // same as score = score + 1
But more interestingly (and more usefully):
alien_count -= num_killed; // same as alien_count = alien_count - num_killed width *= 2; // same as width = width * 2;

These shortcuts can save typing, and also may reduce bugs because there's less chance of mistyping a variable name.  


 

However, we believe that while they're easier to write, for learner-coders they're harder to read, and so you won't see this syntax too often in S2JS examples. But feel free to use it yourself.