+ 5

What's the meaning and how to use x += 5; ?

I have been seeing this on challanges but still not sure what it actually means... Can someone explain. Thank you 😊

9th Dec 2019, 11:29 AM
FrostCore
FrostCore - avatar
20 Réponses
9th Dec 2019, 11:42 AM
Arsenic
Arsenic - avatar
+ 13
Jarred Lazarus You are welcome,👍 I hope it's clear now.😉
9th Dec 2019, 3:39 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 12
Jarred Lazarus Suppose you had an int variable, sum, and you wanted to add 10 to it. How would you do this? Here's one solution : sum = sum + 10; This kind of operation is very common (where 10 is replaced by whatever value you want). //OR You can use the compound addition assignment operator, which looks like: += (plus sign, followed by equal sign). sum += 10; // Add 10 to sum Suppose, instead of adding a value to sum, you wanted to double it? That is, you wanted to multiply it by 2? One way to do this is : sum = sum * 2; // Multiply sum by 2 //OR sum *= 2; // Multiply sum by 2 Read the comments in the lessons as you can find a great examples and explanations. 👍 • https://www.sololearn.com/learn/JavaScript/1131/
9th Dec 2019, 2:42 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 3
x+=5 is x=x+5 x++ is x=x+1
9th Dec 2019, 6:31 PM
Vignesh Rathnam
Vignesh Rathnam - avatar
+ 2
thx for the tip Arsenic . It really helped a lot and I appreciate it much !😊
9th Dec 2019, 11:45 AM
FrostCore
FrostCore - avatar
+ 2
Thank you for replying ~ swim ~ . I gotta be honest some part of it i finish to quick so I didn't really manage to look towarda full detail while finishing it all. I will revise every part of it during my free time. Thanks again ! 😊
9th Dec 2019, 11:48 AM
FrostCore
FrostCore - avatar
+ 2
thanks for the information Danijel Ivanović . 😊
9th Dec 2019, 2:47 PM
FrostCore
FrostCore - avatar
+ 2
It's simple. X=X+5.
9th Dec 2019, 4:16 PM
Suhail 🐈[INACTIVE]
Suhail 🐈[INACTIVE] - avatar
+ 2
thank you @all for replying
10th Dec 2019, 5:19 PM
FrostCore
FrostCore - avatar
+ 2
Maybe this form was first introduced in the C language.
10th Dec 2019, 7:52 PM
Sonic
Sonic - avatar
+ 2
Sonic Oh. I directly start SoloLearn with javascript xD
11th Dec 2019, 3:37 AM
FrostCore
FrostCore - avatar
+ 2
•Simple to understand => var x ; x+=5;//x is undefined and x is initializing to 5 •Easy to learn => x+=5;//x=x+5; x=5;//x=0+5; •In-practical => x=undefined;//x is undefined x=x+5;//x is initializing and adding to 5 Where x = 5; //x is initialize to 5;
11th Dec 2019, 7:29 AM
Vinay Govardhanam
Vinay Govardhanam - avatar
+ 2
x+=5 is logically same as x=x+5 { if x=2 then x+=5 equals to 7 } but it's better practice to write it this way. i hope you got it.
12th Dec 2019, 4:29 AM
navodit yadav
navodit yadav - avatar
+ 1
Example: int x=5; x+=5 <-------> x=x+5 x=5+5 =10 Both are same
9th Dec 2019, 8:20 PM
Mk7
+ 1
x+=5 simply means x = x + 5 Same case applies to all the other mathematical operations. i.e x-=5 means x = x - 5 x/=5 means x = x / 5 x*5 means x = x * 5
10th Dec 2019, 10:17 AM
Samuel Kinuthia
Samuel Kinuthia - avatar
+ 1
x += 5; same as x = x+5;
10th Dec 2019, 3:30 PM
Asvenna Loduni
Asvenna Loduni - avatar
+ 1
Hi x+=5 Means : x= x+5 For example: x=3 x+=5 means x=3+5 Then x=8 Hope help you!
11th Dec 2019, 6:54 AM
FILY CRUZ
+ 1
X=x+5
11th Dec 2019, 8:51 AM
Halikar Swapnil Apparao
Halikar Swapnil Apparao - avatar
+ 1
x=0; x=x+5; result 5
11th Dec 2019, 10:19 AM
Shalva Mkhetsadze
Shalva Mkhetsadze - avatar