Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternatives to console.log?

I was wondering if there are any alternatives to writing something to the console without using console messages. My project removes all console statements before finalizing the build, but in a unique case I need to find a way to display something to the user via the console. Is this even possible without console statements?

like image 660
Doug Avatar asked Oct 07 '14 21:10

Doug


People also ask

What is the difference between console log and console debug?

They are almost identical - the only difference is that debug messages are hidden by default in recent versions of Chrome (you have to set the log level to Verbose in the Devtools topbar while in console to see debug messages; log messages are visible by default).

Is console log the same as return?

console. log() is a function used to print information to the console. return on the other hand is a call to pass some value back up to where the call was made.

What is the difference between document write and console log?

document. write() is used to write HTML to the document using Javascript. console. log() is used to log or display something to the Javascript console.

Is console log the same as print?

The only notable difference between the two is that, when printing an object, console. log gives special treatment to HTML elements, while console.


1 Answers

You can write to console only through Console object. The Console object provides access to the browser's debugging console.

console.log("Failed to open the specified link")

You can use other methods for debugging: info()

console.info('Debug message');

warn()

console.warn('Debug message');

error()

console.error('Debug error message')

time()

console.time(label);

table()

console.table(["apples", "oranges", "bananas"]);

trace()

console.trace();

As for me, I like using console.table() and console.group()

Additional info on the MDN - https://developer.mozilla.org/en-US/docs/Web/API/Console and on the article https://medium.freecodecamp.org/how-to-get-the-most-out-of-the-javascript-console-b57ca9db3e6d

like image 128
Aleksandr Golovatyi Avatar answered Sep 28 '22 00:09

Aleksandr Golovatyi