+ 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)
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👍
+ 1
Now it makes sense. Thanks Vincent
+ 1
Luis Febro Feitoza,
You're welcome👍
+ 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);
0
so adding a string joins it to b + 1, but substracting it works despite it being a string ?