Home > Article > Web Front-end > There are several printing methods in javascript
There are three printing methods in JavaScript, namely window.alert(), document.write() and console.log().
#The operating environment of this article: windows10 system, javascript 1.8.5, thinkpad t480 computer.
In JavaScript, we usually use the following three ways to print data:
Use window.alert() to write the warning box
Use document.write() to write HTML output
Use console.log() to write to browser console
Let’s take a look at how they are used.
Using window.alert()
You can use an alert box to display data:
Example
<!DOCTYPE html> <html> <body> <h1>我的第一张网页</h1> <p>我的第一个段落</p> <script> window.alert(5 + 6); </script> </body> </html>
Use document.write()
For testing purposes, it is more convenient to use document.write():
Example
<!DOCTYPE html> <html> <body> <h1>我的第一张网页</h1> <p>我的第一个段落</p> <script> document.write(5 + 6); </script> </body> </html>
Use console.log()
In the browser, you can Use the console.log() method to display data.
Please activate the browser console via F12 and select "Console" in the menu.
Example
<!DOCTYPE html> <html> <body> <h1>我的第一张网页</h1> <p>我的第一个段落</p> <script> console.log(5 + 6); </script> </body> </html>
Related video tutorial sharing: javascript video tutorial
The above is the detailed content of There are several printing methods in javascript. For more information, please follow other related articles on the PHP Chinese website!