JavaScript Output – Print To Console Using Javascript

Today, we will tell you about methods that will allow you to get javascript output or print to console using javascript. It will help you to use any code and build your own program.

The methods like document.write, console.log and alert are available in javascript output show. Below we will talk in brief to get more idea.

By Using innerHTML

In JavaScript  document.getElementById(id) method is used to access the HTML elements.

Example:

<!DOCTYPE html>
<html>
<body>
<h2>By InnerHTML Method Use</h2>
<p> Hello Paragraph.</p>
<p id="darkweb"></p>
<script>
document.getElementById("darkweb").innerHTML = 40 + 80;
</script>
</body>

By Using document.write()

 We can also access an HTML element In JavaScript by using a document.write() method.never call document.write after the document has finished loading, It will overwrite the whole document.

Example:

<!DOCTYPE html>
<html>
<body>
<h2>By document.write method</h2>
<p> Hello paragraph.</p>
<script>
document.write(98 + 6);
</script>
</body>
</html>

By Using window.alert()

In JavaScript window.alert() is used to call an HTML element.

And  a alert box appears on the screen.

Example:

<!DOCTYPE html>
<html>
<body>
<h2>By window.alert() method</h2>
<p>Hello paragraph.</p>
<script>
window.alert(59 + 6);
</script>
</body>
</html>

By Using console.log()

In JavaScript we call the console.log() method for debugging purposes.F12 on keyboard will activate debugging, then selects the “console” in the debugger menu and then click on run again.

Example:

<!DOCTYPE html>
<html>
<body>
<h2>By Activate Debugging</h2>
<p>console.log print method.</p>
<script>
console.log(59 + 165);
</script>
</body>

JavaScript Print

In JavaScript the window.print() method is used print the current content of the window of a browser. We cannot access any output device from the JavaScript.

Example:

<!DOCTYPE html>
<html>
<body>
<h2>By window.print() Method</h2>
<p>Click me here to print button to print the current page.</p>
<button onclick="window.print()">Click me here to print</button>
</body>
</html>

Join us on facebook with account facebook sign in and get more intrsting tutorial from us and learn more javascript tips.

Stay in touch. Ask Questions.
Lean on us for help, strategies and expertise.

Leave a Reply

Your email address will not be published. Required fields are marked *