The increment and decrement operators are probably the most commonly
used operators when developers want to loop over a collection of data.
Although they might be commonly used and even encouraged in other
languages, in JavaScript, these operators raise a number of concerns
that suggests that developers should avoid them
The two main
concerns that I cover in this video are the general discouragement of
readability and the worry surrounding JavaScript's automatic semicolon
insertion process.
When I say that these operators discourage
readability, what I mean is that they are significantly difficult to
read, especially if you use them a lot. On top of that, the fact these
operators can act as either a postfix or a prefix means that there are
even more options a developer can choose from to use these operators.
The second concern comes from JavaScript's automatic semicolon insertion
promise. One of the nice things about JavaScript is that it doesn't
mandate the use of semicolons. But since JavaScript doesn't exactly know the developer's intent, it can only guesstimate where it should place
semicolons. And these guesstimation process can lead to some unexpected
behaviors, which I demonstrate in the video.
The alternative to
these operators is the assignment operators, specifically the addition
and subtraction assignment operators. These operators are great because
they encourage readability through being more expressive and they
address the automatic semicolon insertion error since they follow a more strict syntax when compared to the increment and decrement operators
🎬 Subscribe to the channel! -
/ @ijemmaonwuzulike
Timestamps:
0:00 Intro
0:26 Overview of Increment and Decrement Operators
1:03 Increment and Decrement Operators in Loops
1:46 What are Postfix and Prefix Operators?
3:57 Why Are The Increment and Decrement Operators "Bad"?
4:26 Concern #1: Discouraging Readability
5:38 Concern #2: Automatic Semicolon Insertion
7:38 The "Good" Practice: The Addition and Subtraction Assignment Operators
8:16 Assignment Operators are More Expressive
9:46 More Alternatives to These Operators
== Let's Connect ==
🐦 Twitter - / ijemmaohno
== Who I Am ==
I'm Ijemma, a frontend software engineer currently working in New York
City. I make videos on all things JavaScript and, more broadly, frontend web development.
#javascript #webdevelopment #softwareengineer