Table of Contents
JavaScript can "display" data in different ways:
innerHTML.document.write().window.alert().console.log().To access an HTML element, JavaScript uses the document.getElementById(id) method.
The innerHTML property defines the HTML content.
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Output</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>Using innerHTML</h4>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 5 + 6;
</script>
</body>
</html>

Result View Example
For testing purposes, it is convenient to use document.write():
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Output</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>Using document.write()</h4>
<script>
document.write(5 + 6);
</script>
</body>
</html>

Result View Example
You can use an alert box to display data:
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Output</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>Using window.alert()</h4>
<script>
window.alert(5 + 6);
</script>
</body>
</html>

Result View Example
For debugging purposes, you can call the console.log() method in the browser to display data.
You will need to activate the browser console with F12, and select "Console" in the menu.
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Output</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>Using console.log()</h4>
<script>
console.log(5 + 6);
</script>
</body>
</html>

Result View Example
JavaScript does not have any print object or print methods.
You cannot access output devices from JavaScript.
The only exception is that you can call the window.print() method in the browser to print the content of the current window.
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Output</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>JavaScript Print</h4>
<button onclick="window.print()">Print this page</button>
</body>
</html>

Result View Example
Document in project
You can Download PDF file.