is a function you can simply use in outputting data (text only) to a user. It works more like a pop up message that display whatever text given to it via its parameter and gives an option to the user to close it (the alert).
is a method of the document
object, which is an object of a webpage. With this method, you can output both text and HTML on any part of your webpage.
document.write("<h2>How are you today?</h2>");
Copy PRACTICE IT
Do not use the document.write()
after a webpage has fully loaded by maybe calling a function where it is being used in outputting text/HTML. It will erase the rest of your webpage contents. See below,
<button onclick='myFunc()'>Click Me</button>
document.write("How are you today?");
Copy PRACTICE IT
Notice how the previous contents were erased.
You will learn about the document
object in subsequent tutorials.
is a method of the console
object, which is an object of a browser's console. With this method, we can log messages/texts on a browser's console.
should only be use for development and testing purposes as such messages are not directly outputted to the user rather till they open their browser's console and that will be if they even know a message is there or something of such even exists.
- The data should be text only. HTML can not be interpreted on the alert pop up.
- If you have HTML markups in a text to be outputted by the alert, the markups will be display just the way they are. No interpretations.
- document.write() is yet another easy way to write both text and HTML contents on a webpage when it is loading.
- The document.write() should not be use after a webpage have fully loaded. It will erase all other contents on a webpage.
- Yet again, there is the console.log() to log messages on a browser's console.