Why the output is coder? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why the output is coder?

<div id ="test"></div> <script> var a =document.getElementById("test"); a.innerHTML="hello"; a.innerHTML="CODER!"; </script>

17th Oct 2017, 4:04 AM
Saurabh Rauthan
Saurabh Rauthan - avatar
5 Answers
+ 4
if you want the output is helloCODER!, concat the both a variable <div id ="test"></div> <script> var a =document.getElementById("test"); a.innerHTML="hello"; a.innerHTML+="CODER!"; </script>
17th Oct 2017, 5:56 AM
MBZH31
MBZH31 - avatar
+ 3
CODER was overwrite hello
17th Oct 2017, 4:29 AM
林偉雄
林偉雄 - avatar
+ 3
a.innerHTML = "CODER!" is overwriting previous value of a.innerHTML
17th Oct 2017, 9:58 AM
stn
stn - avatar
+ 2
u want output hello CODER u need use "+="
17th Oct 2017, 4:30 AM
林偉雄
林偉雄 - avatar
+ 2
thanx all ...what sololearn is today is all about you !!
17th Oct 2017, 11:09 AM
Saurabh Rauthan
Saurabh Rauthan - avatar