+ 1

What is console.log(*) used for in JavaScript

I didn't come across it in the js tutorial but am seeing frequently now in examples

10th Nov 2018, 7:32 AM
Meyo
Meyo - avatar
6 Réponses
+ 7
I suppose it depends on what you mean by purpose. If you are using document.write() for debugging purposes, then yes. However, document.write() obviously works differently from console.log() in that one affects the page while the other does not. Sometimes, you'll want to output information that will present better in console.log(). A few examples are: - Serialized JSON objects - Sequence of actions with timestamps posted for each step or iteration in a looping construct. It should also be noted that console.log() will not require HTML for simple formatting like line breaks as document.write() does. I almost rarely use document.write() for debugging purposes. Console.log() is more appropriate in that is doesn't impact the UI.
10th Nov 2018, 8:00 AM
David Carroll
David Carroll - avatar
+ 5
console.log() is used for logging from your code to the console window, which is a panel in your browser development tools. This is a great way to log code activity for debugging purposes.
10th Nov 2018, 7:44 AM
David Carroll
David Carroll - avatar
+ 2
David Carroll what I meant.
17th Jan 2019, 7:10 PM
Markpeach96
Markpeach96 - avatar
+ 1
Does it serve the same purpose as document.write. if no, which should be used in the actual coding process
10th Nov 2018, 7:47 AM
Meyo
Meyo - avatar
+ 1
You can use console.log to write to the log file. If your browser supports debugging, you can use theconsole.log method to displayJavaScript 
17th Jan 2019, 6:09 PM
Markpeach96
Markpeach96 - avatar
+ 1
Markpeach96 I wasn't aware that console.log() could be used to write to a file. Did you mean to say write to console?
17th Jan 2019, 7:08 PM
David Carroll
David Carroll - avatar