New course! Every coder should learn Generative AI!
Try a free lesson+ 2
What does ++ and
I encounter code questions with a++, b++, a--, b--, etc. I have no idea what does ++ or -- mean. Can anyone help me? I'm flustered!!!! 😫😫😫😱😱😱
5 Answers
+ 9
Those are shorthand operators, for example:
(a++) is the same as (a = a + 1 and a += 1) basically it will increment or decrease the variable depending on what operator you use, using -- would obviously decrease it. :)
+ 8
One thing to note:
Using ++ or -- after a variable will FIRST return the value of the variable and THEN increase/decrease it by 1, if you have ++/-- in front of the variable it's the other way around.
Example:
a = 5;
b = ++a;
//now a is 6 and b is also 6
a = 5;
b = a++;
//a is 6 again, but b is 5 (first a++ returns the value of a, 5 in this case, and after that it increases a by 1)
+ 3
++ make plus 1 to a variable. An example:
var x = 2
var y =2
var resu = (x + y)
document.write(resu)
0
Thx dude. Phew!
0
привет всем