1

For some reason using

    var sample = "test";
    print(sample);

the print function doesn't print the string on the web browser , however it literally uses the print function on my chrome browser . any idea why ? Im actually learning javascript from http://eloquentjavascript.net/ and it uses the print function too.

Napmi
  • 439
  • 2
  • 11
  • 24
  • 5
    if you want to print something on the page use `document.write()` if you want to print something for debugging purpose use `console.log()` – T J Mar 22 '14 at 14:28
  • 2
    As the book says, "`print` is not a standard JavaScript function, browsers do not provide it for you, but it is made available by this book, so you can use it on these pages". – OnlyThenDidIReckonMyCurse Mar 22 '14 at 14:29
  • @TilwinJoy, that is an answer in itself. Place that as an answer along with some extra explanation. – sshashank124 Mar 22 '14 at 14:31
  • @JilwinJoy Using document.write [is often discouraged for various reasons](http://stackoverflow.com/a/802943/975097), so it might be better to use another function. – Anderson Green Mar 22 '14 at 14:52

1 Answers1

0

The window.print() method opens the print dialog to print the current document, Not part of any standard. ( from MDN)

If you want to print something in your page, use document.write() function. The text you write is parsed into the document's structure model

read more at MDN - document.write()

if you want to print something for simple debugging purpose, use console.log(), which prints the output in browsers console. read more at MDN - console.log()

T J
  • 40,740
  • 11
  • 73
  • 131