Writing to output window of Javascript
JavaScript Display Possibilities
JavaScript can "display" data in different ways:
1. Writing into an HTML element, usinginnerHTML
.2. Writing into the HTML output using
document.write()
.3. Writing into an alert box, using
window.alert()
.4. Writing into the browser console, using
console.log()
.Example 1
<!DOCTYPE html>
<html>
<body>
<h1>My First Web Page</h1>
<p>My First Paragraph</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 5 + 6;
</script>
</body>
</html>
Output
11
Example 2
<!DOCTYPE html>
<html>
<body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<script>
document.write(5 + 6);
</script>
</body>
</html>
Output
11
Example 3
<!DOCTYPE html>
<html>
<body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<button type="button" onclick="document.write(5 + 6)">Try it</button>
</body>
</html>
Output
11