0

how to assign value of z = ++b without changing the value of b.

var a = 3, b = 2, z = ++b, z = b + a; console.log(z); console.log(b); //Output: (1+2)+3 = 6 //Output: (1+2) = 3 I want to get z=b+1=3 but at the same time I want to use b later as the first given value b=2 how to do that

17th Aug 2019, 7:07 AM
Safaa Alnabhan
Safaa Alnabhan - avatar
4 Réponses
+ 5
z=b+1, sets Z to 3 and doesn't increase b
17th Aug 2019, 7:10 AM
Elva
Elva - avatar
0
Can we do that with arrays forexample to increase a string for many times or make loop?
17th Aug 2019, 2:18 PM
Safaa Alnabhan
Safaa Alnabhan - avatar
0
Elva
17th Aug 2019, 2:18 PM
Safaa Alnabhan
Safaa Alnabhan - avatar
0
What do you mean increase string? Considering arrays you can do a = myarr[0]+1, value of first element of myarr won't change but a will be that element +1, same thing as previous answer
17th Aug 2019, 3:36 PM
Elva
Elva - avatar