This lessons mentions, in passing, the general form for assigning a new value to a variable based on its existing value:
i++ is the equivalent of i = i + 1
I.e., the form of variable = variable <operator> <expression>
Should this technique be explicitly explained, either in this lesson or a prior one? I only ask because when I first learned this paradigm many years ago it seemed pretty strange at the time. How can I have the same variable on both sides of the equals sign? Doesn’t that create some kind of weird infinite loop? Such were my questions back then
Anyway, what do you guys think? Did any of you trip up on this when you were learning?
Still, it might be confusing to make reference to a technique that hasn’t been explained yet. Perhaps the former lesson can simply state that i++ is the way to increment a number, and then explain in the latter lesson that it’s actually a short cut? Or, as most programming tutorials do, perhaps you could move the increment/decrement lessons to appear after the one that covers modification assignments.
Hi @joechan3! Thanks for the advice. The FCC contrib.md says to wait for 3rd party confirmation before entering a new bug, so that’s why I posted here first, hoping to find someone else who agreed But I suppose there’s no harm in creating the issue and having the discussion in Github directly.
The way I view it and the way I think JavaScript interprets it, is kind of like
variable = "value of variable"+ 1
the equals symbol creates that distinction. if the variable = 1 you aren’t saying 1 = 1+1, you’re saying the 'variable which already has a value of 1 is NOW equal it’s current value + 1.
I always found i++ much more confusing than i = i + 1. Especially since in other languages there’s also ++i (try to reason about this one and its difference to i++!).
Compared to that, i = i + 1 seems very intuitive to me.
More fun are the compound assignment operators, like i += 1 or even i **= 2…
Jesus… and I thought I had escaped it when I started doing Javascript, I never actually see anyone use ++i now, while I saw it used in Java and C-blabla all the time.