There are different ways of displaying information in JavaScript. for example:
- document.write
- window.alert
document.write
Document.Write is one of the methods of displaying data using JavaScript. Document.Write will display results in HTML.
- For displaying messages we can place message in double quotes.
- For displaying HTML we can use Document.Write and place html code in double quotes.
- For any calculations we don’t need to use double quotes.
1 2 3 4 5 6 7 |
<script type="text/javascript"> document.write("This is output message using document.write") document.write("<BR>") document.write("Welcome to javascript") document.write("<BR>") document.write(9+5) </script> |
window.alert
window.alert can be used to display data in alert format.
- For displaying messages we can place message in double quotes.
- For displaying HTML we can use window.alert and place html code in double quotes.
- For any calculations we don’t need to use double quotes.
1 2 3 4 5 6 7 |
<script type="text/javascript"> document.write("Welcome to javascript") window.alert("This is output message using document.alert") document.write("<h1>This is HTML heading one using javascript window.alert</h1>") document.write("<BR>") document.write(9+5) </script> |