Skip to content

Commit

Permalink
Describe double plus/minus operators. Closes loverajoel#223
Browse files Browse the repository at this point in the history
  • Loading branch information
Filip Figiel committed Feb 20, 2016
1 parent a5c4183 commit cc4953e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions _posts/en/2016-02-04-assignment-shorthands.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,32 @@ n --; n = n - 1;

````

### `++` and `--` operators

There is a special `++` operator. It's best to explain it with an example:

````javascript
var a = 2;
var b = a++;
// Now a is 3 and b is 2
````

The `a++` statement does this:
1. return the value of `a`
2. increment `a` by 1

But what if we wanted to increment the value first? It's simple:

````javascript
var a = 2;
var b = ++a;
// Now both a and b are 3
````

See? I put the operator _before_ the variable.

**Exercise:** find out what the `--` operator does!

### If-else (Using ternary operator)

This is what we write on regular basis.
Expand Down

0 comments on commit cc4953e

Please sign in to comment.