Console.log on JavaScript


I can't understand console.log. what does it do? why do we need it?
Please explain me like I'm a baby.


Its just a way you make stuff appear as an output on the console. The console itself echoes value you enter but only the last of them, so if you want to see more than just the last (it does not even work in case of undefined) than you would need to use console.log in this way:

console.log("Here comes whatever you want to print to the console");


it also helps with communication with the pc


Why not just write the content in qoutes?

"Here comes whatever you want to print to the console"`


Please explain me how it does


Because then it is just a value and is only printed if it is the last in your code. Try it:


you'll only see the 3.


the console.log function can help you to find why your code don't work properly...(i can relate)
but to write in a web page you hav eto use document.write it do the same but on the web page


console.log would still work, but it would write to the web console a tool few people are even aware of :smile:
But I guess you wouldn't use document.write either but rather change the value of a div or another html structure as document.write has some problems: