mirror of
https://github.com/airbnb/javascript.git
synced 2026-01-14 00:28:25 -05:00
[guide] Mention both num++ and num ++
This commit is contained in:
@@ -1547,15 +1547,15 @@ Other Style Guides
|
||||
<a name="variables--unary-increment-decrement"></a><a name="13.6"></a>
|
||||
- [13.6](#variables--unary-increment-decrement) Avoid using unary increments and decrements (++, --). eslint [`no-plusplus`](http://eslint.org/docs/rules/no-plusplus)
|
||||
|
||||
> Why? Per the eslint documentation, unary increment and decrement statements are subject to automatic semicolon insertion and can cause silent errors with incrementing or decrementing values within an application. It is also more expressive to mutate your values with statements like `num += 1` instead of `num ++`. Disallowing unary increment and decrement statements also prevents you from pre-incrementing/pre-decrementing values unintentionally which can also cause unexpected behavior in your programs.
|
||||
> Why? Per the eslint documentation, unary increment and decrement statements are subject to automatic semicolon insertion and can cause silent errors with incrementing or decrementing values within an application. It is also more expressive to mutate your values with statements like `num += 1` instead of `num++` or `num ++`. Disallowing unary increment and decrement statements also prevents you from pre-incrementing/pre-decrementing values unintentionally which can also cause unexpected behavior in your programs.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
|
||||
let array = [1, 2, 3];
|
||||
let num = 1;
|
||||
num ++;
|
||||
-- num;
|
||||
num++;
|
||||
--num;
|
||||
|
||||
let sum = 0;
|
||||
let truthyCount = 0;
|
||||
|
||||
Reference in New Issue
Block a user