0

var n = 5 ; alert(n-=2) = 3 or alert(n-2)= 3 . When would anyone use ( -=2 ) when ( n-2 ) is straight forward ? 🤔🤔🤔🤔

29th Jun 2021, 11:32 AM
Theresco
Theresco - avatar
2 odpowiedzi
+ 3
when you use a-=2 the value of a decreases 2. when you use a-2 the value of a doesn't decrease. So the value of a still remains the same. Here is an example: https://code.sololearn.com/Wa23A179a20A
29th Jun 2021, 11:39 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 2
if you want to assign the result of calculation to variable n use n -= 2
29th Jun 2021, 11:42 AM
Solo
Solo - avatar