+ 1
Can anyone say whether the following code is possible or not ? If possible then please give expected output and explanation.
a=prompt(); document.write((a+=10)+"<br/>"+(a-=11));
4 Antworten
+ 6
Why use a+=10 if you can simply use a+10 ? += only changes the value of the variable, but does not return anything.
+ 2
Why don't you try it yourself 🙂🙃👇
https://code.sololearn.com/W1hcwlLp15w7/?ref=app
+ 2
I have tried it and I have got the output. But I am seeking for the explanation of the output…
0
Prompt returns a string.
When JavaScript tries to operate on a "wrong" data type, it will try to convert the value to a "right/correct" type.
5 + null // returns 5 because null is converted to 0
"5" + null // returns "5null" because null is converted to "null"
"5" + 2 // returns "52" because 2 is converted to "2"
"5" - 2 // returns 3 because "5" is converted to 5
"5" * "2" // returns 10 because "5" and "2" are converted to 5 and 2
reference from W3Schools.com
https://code.sololearn.com/WcDytXNgw5XL/#js