What are the three output methods of JavaScript?

青灯夜游
Release: 2021-11-24 14:07:54
Original
5381 people have browsed it

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>
Copy after login

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>
Copy after login

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>
Copy after login

【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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template