Home >Web Front-end >Front-end Q&A >What are the three output methods of JavaScript?
Three output methods of JavaScript: 1. Pop up a warning box for output, the syntax is "alert("output information")"; 2. Console output, the syntax is "console.log("output information")" ;3. Browser visible area output, syntax "document.write("output information")".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
1. alert(year) pops up a warning box
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <script> // 定义一个变量 存储一个人的年龄 var year = 23; alert(year) </script> </body> </html>
2. console.log() console output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <script> // 定义一个变量 存储一个人的年龄 var year = 23; console.log(year); </script> </body> </html>
Console after pressing F12
3. Output document.write() to the browser’s visible area
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <script> // 定义一个变量 存储一个人的年龄 var year = 23; document.write(year) </script> </body> </html>
【Related recommendations: javascript learning tutorial】
The above is the detailed content of What are the three output methods of JavaScript?. For more information, please follow other related articles on the PHP Chinese website!