close

How to print to console using javascript?

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn How to print to console using javascript? in javascript. So Here I am Explain to you all the possible methods here.

Without wasting your time, Let’s start This Article.

How to print to console using javascript ?

  1. How to print to console using javascript ?

    to print to console using javascript A note about 'throw()' mentioned above. It seems that it stops execution of the page completely (I checked in IE8) , so it's not very useful for logging “on going processes” (like to track a certain variable…)

  2. How to print to console using javascript ?

    to print to console using javascript A note about 'throw()' mentioned above. It seems that it stops execution of the page completely (I checked in IE8) , so it's not very useful for logging “on going processes” (like to track a certain variable…)

Method 1

console.error(message); // Outputs an error message to the Web Console
console.log(message); // Outputs a message to the Web Console
console.warn(message); // Outputs a warning message to the Web Console
console.info(message); // Outputs an informational message to the Web Console. In some browsers it shows a small "i" in front of the message.

You also can add CSS:

console.log('%c My message here', "background: blue; color: white; padding-left:10px;");

Method 2

A note about ‘throw()’ mentioned above. It seems that it stops execution of the page completely (I checked in IE8) , so it’s not very useful for logging “on going processes” (like to track a certain variable…)

My suggestion is perhaps to add a textarea element somewhere in your document and to change (or append to) its value (which would change its text) for logging information whenever needed…

Summery

It’s all About this article. Hope all method helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you? Thank You.

Leave a Comment