+ 1

Why the output equals 75? Could someone explain the calculation of C variable?

let a = 1; let b = 2; let d = "8"; let c = d + (a = b + 1) - d; alert(c)

14th Oct 2018, 6:57 PM
Luis Febro 🇧🇷
Luis Febro 🇧🇷 - avatar
5 odpowiedzi
+ 3
let a = 1; let b = 2; let d = "8"; let c = d + (a = b + 1) - d; alert(c) d = A string so it will be not added with the (a=b+1), instead it joins it: ("8"+(1=2+1)=83 - d = a substraction what can be done: ("8"+(1=1+2)-8=75 Sum:: ("8"+(1=1+2)-8=75 ^ ^ ^ ^ ^ 1 2 3 4 5 #1 Variable d string that contains 1 character is "8" #2 variable a contains a number is 1 == 81 #3 variable a is b contains a number is 1 == 81 #4 number hold a value of 2 == 83 #5 variable d string is a substraction of 8 == 75 Hope this helps👍
14th Oct 2018, 7:27 PM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar
+ 1
Now it makes sense. Thanks Vincent
15th Oct 2018, 2:19 AM
Luis Febro 🇧🇷
Luis Febro 🇧🇷 - avatar
+ 1
Luis Febro Feitoza, You're welcome👍
15th Oct 2018, 11:29 AM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar
+ 1
Enn Moad, Have a look👍:: https://code.sololearn.com/WC06Obv6YOm2/?ref=app var num = 10, str = "8"; console.log(num-str+"\n"+num+str+"\n"+num*str+"\n"+num/str+"\n"+num%str);
15th Oct 2018, 1:28 PM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar
0
so adding a string joins it to b + 1, but substracting it works despite it being a string ?
15th Oct 2018, 1:20 PM
Enn Moad
Enn Moad - avatar