views:

345

answers:

7

What's your favorite way of testing javascript code snippets?

I like to use the browser's address field directly:

javascript:void(document.getElementById("textbox").style.display='none'))
javascript:void(document.write("Testing"))
javascript:alert(parseFloat("33.33"))

If using the latter trick, don't forget to wrap everything in a void() call or an alert() call, lest the page will be blanked out.

Alternatively, there is the Firebug extension on firefox in which you can edit javascript code arbitrarily.

Any other interesting ways out there?

+3  A: 

I use Firebug for pretty much everything JavaScript.

Galwegian
+6  A: 

Firebug Console Logging

jonstjohn
+1  A: 

If you want to debug and run Javascript on the fly on IE, you can alos give Debugbar a try. It works great.

Johan Buret
I'll have to try this one out; I've been hurting for a Firebug-equivalent for IE. :-)
Ben Blank
+3  A: 

I use Firebug by far the most times.
Otherwise I use the addressbar, or simply adding a button or link on the page.

Eibx
A: 

In order to test small scripts across different browsers, I have a html file lying around which just contains

<pre><script>
</script></pre>

Logging gets done via document.writeln().

Christoph
+1  A: 

I use the tryit.asp on link text on w3school as I normally check my html with that site anyway. It also allows me to try variations before I go to far.

Dave
+3  A: 

You can use JSBin to test snippets of code with snippets of html and some js frameworks.

heeen
Just want to say thanks for the link!
Eibx
Great tool! Never saw this before.
Michael La Voie