<div id="myId"></div> <script> var x = "Sheo Narayan"; var y = 'SN ITFunda'; document.getElementById("myId").innerHTML = x + "<br/>" + y; </script>
In the above code snippet we have two strings in script block in that one is "Sheo Narayan" which is in double quotes and another one is 'SN ITFunda' which is in single quotes, below that there is an
which returns the element that has Id "id=myID" in the HTML page.
The variable 'x' with string "Sheo Narayan" and varible 'y' with string 'SN ITFunda' appeared in seperate lines in the output, because we have given the breakline <br/> in between them.
In the same way we can quote inside a string also, in case if we want to insert the quotes directly without inserting any special characters in the string, there must be difference in inside and outside used quotes, if we use single quotes outside the string, we should only use the double quotes inside the string and in the same way if we use double quotes outside the string, we should only use single quotes inside the string.
<div id="getId"></div> <script> var a = "This is 'DotNetFunda'"; var b = 'This is "TechFunda"'; var c = "This is 'KidsFunda' & 'FarmingFunda'"; document.getElementById("getId").innerHTML = a + "<br/>" + b + "<br/>" + c </script>
In the above code snippet we have three strings along with the variables a, b, c. We used the different quotes inside and outside the strings. Three strings are appeared one after the other in the new line because we use the breakline
<br/> in between them.
Views: 2920 | Post Order: 62