In JavaScript, printing generally means displaying output. Depending on where you want the output to appear, you can use several methods:

1. Print to the Console

Use console.log():

console.log("Hello, World!");

This shows in the browser’s developer console.

2. Print to the Web Page

Use document.write() (not recommended for modern apps, but still useful for quick demos):

document.write("Hello, World!");

Or modify an element on the page:

<code><p id="output"></p>
<script>
 document.getElementById("output").innerText = "Hello, World!";
</script></code>

3. Trigger the Browser’s Print Dialog

Use window.print():

window.print();

Need Help With Javascript Development?

Work with our skilled Javascript developers to accelerate your project and boost its performance.

Hire JavaScript Developers

Support On Demand!

Related Q&A