简体   繁体   中英

How do I run JavaScript in a console like environment?

I'm trying to follow the the examples here

http://eloquentjavascript.net/chapter2.html

and

print('blah');

Keeps trying to send to a physical printer when run in a browser. I just want console output.

If 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.org/web/20150101222740/http://anemonesoft.com/os/cottage/doc/tutorial/console.html

You can run javascript interactively from the command line. This blog post from ajaxian.com describes how to use the built-in javascript shells on Windows and Mac OS. When you're feeling especially lazy, you can also type commands into a browser-based javascript interpreter like this one .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM