From the course: JavaScript: Best Practices for Functions and Classes

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Avoid unary increments and decrements

Avoid unary increments and decrements - JavaScript Tutorial

From the course: JavaScript: Best Practices for Functions and Classes

Start my 1-month free trial

Avoid unary increments and decrements

- [Instructor] At first blush, urinary increments and decrements have some appeal. They combine two operations into one with a minimum of characters. But that power can trip up even the most experienced programmers. So like a lot of developers, I prefer to steer clear of these. I like my code to be easy for me and other people to read and understand. I find that when I'm reading code that uses unitary operators, it can take me a moment to fully understand what these operators are doing. It's also too easy for my taste to confuse plus plus, with a single concatenation or addition and minus minus with subtraction. Urinary operators also work as prefix or postfix operators. Meaning you can put them before or after an operand with different results. Mistakenly, putting an operator in the wrong place can result in a bug that's a real challenge to find and fix. Finally, while whitespace generally doesn't affect the meaning of…

Contents