I'm trying to follow the the examples here
.html
and
print('blah');
Keeps trying to send to a physical printer when run in a browser. I just want console output.
I'm trying to follow the the examples here
http://eloquentjavascript/chapter2.html
and
print('blah');
Keeps trying to send to a physical printer when run in a browser. I just want console output.
Share Improve this question asked Jan 24, 2012 at 20:55 HoaHoa 20.4k28 gold badges82 silver badges111 bronze badges 1- "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" – gen_Eric Commented Jan 24, 2012 at 20:58
3 Answers
Reset to default 10If you want something simple, the Chrome console will let you run JavaScript on the fly. To print text you can use console.log('blah');
And if you want to print multiple values, you can just list them all out as arguments (no need to concatenate) console.log("a", "b", "c", 1, 2, 3);
You can bring it up with control-shift i
then select the console tab on the far right. And of course FireBug has a similar feature if you're more of a FireFox fan.
Almost all modern browsers have developer tools, which includes the a console. Look for developer tools in your browser, then look for the console.
Once you've found it, you can enter expressions manually, or place console.log()
in the desired places in your code.
Note: Once you get used to the console, it will replace the need for the ever so annoying alert(myVar)
.
Additional Info
Here's a decent overview/tutorial on using the console: https://web.archive/web/20150101222740/http://anemonesoft./os/cottage/doc/tutorial/console.html
You can run javascript interactively from the mand line. This blog post from ajaxian. describes how to use the built-in javascript shells on Windows and Mac OS. When you're feeling especially lazy, you can also type mands into a browser-based javascript interpreter like this one.