0
How do we get the answer 75? Would appreciate the clear explanation for noob.
var a = 1; var b = 2; var d = ā8ā; var c = d + (a = b + 1) - d; console.log(c);
3 Answers
+ 3
First in the brackets a = 2 + 1 => 3. Then d is a string and applying concatenation to "a" variable which is 3 => "83" as string. After that there is a "-" sign => it means operation with numbers, so 83 is interpreted as number and the result is 83 - 8 => 75. Hope my explanation can help you.
+ 2
1) (a = b + 1) is 3 (the number), as expression in parentheses gets the result calculated for 'a'
2) d + (a = b + 1) is "83" (the string), as the type of "d" is string, so "8" + 3 is "83", because the type of the value of the '3' is converted to string and '+' for strings means the string concatenation
3) at last 'd + (a = b + 1) - d' is equal to ' "83" - "8" '. There is no '-' operation for strings in JavaScript, so these types are converted to numbers and we get 75 as the result.
0
thanks to you, guys. now Iām clear