From 2a28b9c82f04a05462cfef025b6c791538472232 Mon Sep 17 00:00:00 2001 From: Alexey Raspopov Date: Mon, 12 Sep 2016 10:06:15 +0300 Subject: [PATCH] move #variables--unary-increment-decrement to correct section --- README.md | 59 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index ce0de3fd..0c99262f 100644 --- a/README.md +++ b/README.md @@ -1285,35 +1285,6 @@ Other Style Guides } ``` - - [13.5](#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. - - ```javascript - // bad - - let array = [1, 2, 3]; - let num = 1; - let increment = num ++; - let decrement = -- num; - - for(let i = 0; i < array.length; i++){ - let value = array[i]; - ++value; - } - - // good - - let array = [1, 2, 3]; - let num = 1; - let increment = num += 1; - let decrement = num -= 1; - - array.forEach((value) => { - value += 1; - }); - ``` - **[⬆ back to top](#table-of-contents)** @@ -1487,6 +1458,36 @@ Other Style Guides // the same applies for `const` ``` + + - [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. + + ```javascript + // bad + + let array = [1, 2, 3]; + let num = 1; + let increment = num ++; + let decrement = -- num; + + for(let i = 0; i < array.length; i++){ + let value = array[i]; + ++value; + } + + // good + + let array = [1, 2, 3]; + let num = 1; + let increment = num += 1; + let decrement = num -= 1; + + array.forEach((value) => { + value += 1; + }); + ``` + **[⬆ back to top](#table-of-contents)**