+ 1
How is it possible for document.write (1 + "<br/>") ; gives 1 and a line break and while document.write(1 + <br/>) doesn't.i don't understand the concept because it only understands the string..someone please help am confused
4 Answers
+ 5
document.write(1+<br/>) is not possible because "+" is concatination and it use to add variable.
+ 2
+ treated as concatenation operator and it works with strings, and strings enclosed in quotation marks..
+ 2
i + <br/> is considered as two strings so o/p is
I<br/> but "<br/>" the code is executed as HTML break tag.so o/p is I and break
+ 2
Html and JavaScript are two different languages. it means that if you do this in HTML: <p> dothemath () </p> then HTML won't trigger the function.
The catch here is, document.write is a function that writes to the HTML file. JavaScript can write stuff in the HTML even if it doesn't understand or make sense of. it can just write anything to the document as long as it's a string. after that, it's up to the HTML to make sense of it, or not.