Javascript | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

Javascript

What is the difference between "sum += (variable)" and "sum =+ (variable)"?

22nd Feb 2020, 5:56 AM
Yan Yan
Yan Yan - avatar
7 Respuestas
22nd Feb 2020, 6:45 AM
Gabriel Ilie
Gabriel Ilie - avatar
+ 2
Yes. You are correct, but this was not the case.
22nd Feb 2020, 8:02 AM
Gabriel Ilie
Gabriel Ilie - avatar
+ 1
First is equivalent with sum = sum + (variable). This means that the value of sum is increased by the value of (variable) Second is equivalent with sum = (variable). This means that the value of sum becomes the value of (variable)
22nd Feb 2020, 6:41 AM
Gabriel Ilie
Gabriel Ilie - avatar
0
Gabriel Ilie, Hi! why do you put the "nr" variable in brackets in your code example?
22nd Feb 2020, 7:29 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
No reason. Just to note that the brackets have no impact in the result
22nd Feb 2020, 7:56 AM
Gabriel Ilie
Gabriel Ilie - avatar
0
in some cases, parentheses have a value. in them, the expression is evaluated first
22nd Feb 2020, 7:58 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
maybe in this question the second part of the example refers to the use of the unary plus? that is, if a negative value is stored in a variable, then plus converts it to a positive value
22nd Feb 2020, 8:06 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar