0
Hey guys, what is the difference between ++1 and 1++? And also when used with minus. Gets me confused.
var a=++1 var b= 1++ var c = a+b alert ("c") ; What will be the outcome?
9 Réponses
+ 11
Refer to my variables code for a reference
+ 8
You should check this question 😉: https://www.sololearn.com/Discuss/160327/?ref=app
+ 5
this won't work. I don't really know for JavaScript, but in C++ this would cause an error.
++ means take the variable and add one to it.
so if x is 2 and you say x++ this will lead to x=x+1, so x=2+1
since variable names must not start with a number and in your example 1 would be processed as a variable, you'll get an error, because 1++ would read as 1=1+1 and as we all know 1=2 is false.
+ 4
it was just an example. in examples it doesn't matter if the variable names are a, b, c, x or cookieMonsterDominatorOfTheWorld9000X.
fact is, that a=1++ will cause an error, because ++ and -- include assignments. and you can't assign anything to a number.
+ 4
okay, let's start over: what do you want your code to do?
+ 3
++1& 1++ are operators that increment a value while --1 & 1-- they decrement a value.In ++1 you increment the value before assigning it while 1++ you assign the value is first assigned then incremented.
0
I used the variables a, b and c in my question. So i don't really you answering with "x" @Mario
0
I know you're tryna help. But you gotta bring it down a few notches my level. I'm kinda new to programming man. @Mario
0
Actually i wasn't making anything in particular. Was just tryna understand how it works. Encountered it on Challenges and kept loosing.