Console.log on JavaScript


#1

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


#2

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");

#3

it also helps with communication with the pc


#4

Why not just write the content in qoutes?

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

#5

Please explain me how it does


#6

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

"1"
"2"
"3"

you'll only see the 3.


#7

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


#8

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: