Writing to The HTML Document
For testing purposes, you can use JavaScript to write directly to the HTML document
Example:
Example:
If your browser supports debugging, you can use the console.log() method to display JavaScript values in the browser.
Activate debugging in your browser with F12, and select "Console" in the debugger menu.
Example:
For testing purposes, you can use JavaScript to write directly to the HTML document
Example:
Use document.write for testing only. If you execute it, on a loaded HTML document, all HTML elements will be overwritten.<!DOCTYPEhtml> <html> <body> <h1>My First Web Page</h1> <p>My first paragraph.</p> <script> document.write(Date()); </script> </body> </html>
Example:
Writing to The Console<!DOCTYPEhtml> <html> <body> <h1>My First Web Page</h1> <p>My first paragraph.</p> <buttononclick="myFunction()">read it</button> <script> function myFunction() { document.write(Date()); } </script> </body> </html>
If your browser supports debugging, you can use the console.log() method to display JavaScript values in the browser.
Activate debugging in your browser with F12, and select "Console" in the debugger menu.
Example:
<!DOCTYPEhtml> <html> <body> <h1>My First Web Page</h1> <script> a = 5; b = 6; c = a + b; console.log(c); </script> </body> </html>
Did You Know?
Debugging is the process of testing, finding, and reducing bugs (errors) in computer programs. The first known computer bug was a real bug (an insect), stuck in the electronics.