-1

When using JavaScript in HTML, console.log(); is replaced with document.write();. But console.log(); is still perfectly usable, but I don't exactly know when it would be used, seeing as it doesn't print anything. And no site I've visited has had any real information about this.

document.write("Thanks!!");

Domani Tomlindo
  • 239
  • 1
  • 5
  • 12
  • Open your browser's Javascript console to see `console.log` in action. And `document.write` is hardly ever something useful to use. You'd rather manipulate the DOM with somewhat more complex but fitting methods. – deceze Oct 17 '18 at 11:41
  • 1
    I don't think I've ever seen `document.write` used in any serious code. It's only ever been used as a debugging tool to output some information. And even then, mostly in examples simply because it's easy to draw on a page in an iframe or something. `console.log` is always more convenient, since it doesn't randomly modify your page and probably break formatting when you simply want to see what the value of something is. – VLAZ Oct 17 '18 at 11:43
  • *"console.log vs document.write"* `console.log`, definitely, Always `console.log` ;) the console can not just log multiple arguments, but it can also log every type of value, not just strings. check this `console.log(window)` and then press on the little triangle – Thomas Oct 17 '18 at 11:48
  • have you read this..https://stackoverflow.com/a/35683033/7035903 – shreyas d Oct 18 '18 at 05:36

4 Answers4

2

console.log logs to the console. If you use Chrome, press F12 and find it there. document.write writes to the document, i.e. to your HTML page. document.write is almost never used nowadays, because it replaces the whole page with what you write, and this is not much useful.

Nurbol Alpysbayev
  • 19,522
  • 3
  • 54
  • 89
0

This string will be placed on the website.

document.write("Thanks!!");

This string will be placed in the browser console (pres F12 to toggle console)

console.log("Thanks!!");

document.write("Thanks!!");
console.log("Thanks!!");
J.vee
  • 623
  • 1
  • 7
  • 26
0

console.log is used to write logs to the console, mainly for debugging purposes https://developer.mozilla.org/en-US/docs/Web/API/Console/log

document.write is used to write markup to the document, and if executed after page load it replaces everything in the header and body tag with the markup given to the method. https://developer.mozilla.org/en-US/docs/Web/API/Document/write

lazreg87
  • 953
  • 4
  • 16
0

I think you are new to Java Script. console.log() is used to for debugging purpose. While document.write() is used when you want some thing to be written on DOM of browser.