Home  >  Article  >  Web Front-end  >  What are the three output methods of JavaScript?

What are the three output methods of JavaScript?

青灯夜游
青灯夜游Original
2021-11-24 14:07:445329browse

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")".

What are the three output methods of JavaScript?

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

Three output methods of JavaScript

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn